[R] convert wind direction from degrees to basic compass directions

Joshua Wiley jwiley.psych at gmail.com
Sat Oct 23 22:50:47 CEST 2010


On Sat, Oct 23, 2010 at 1:40 PM, will phillips <will.phillips at q.com> wrote:
>
> Hello,
>
> I have a data set that includes a predictor variable "wind direction".  This
> variable is in degrees with 0=North.  I've put this predictor into a linear
> model and its coefficient is far from significant.
>
> I was thinking about converting this variable into 8 factors "north"
> "northwest" "west" and on around to see if that helps.

My understanding is that if you have continuous data, it is best to
leave it that way rather than convert it to categorical data.  Is this
theory driven or just in hopes of getting a p-value below some level?
In any case if you do this, you may also want to consider what
contrasts you use to code your 8 level factor for your model.

>
> If I add 360 to every entry I know that anything from 337.5 to 382.5 would
> be "north", anything from 382.51 to 427.5 would be "northwest", etc...
>
> I'm fairly new to R and I can assign labels to values in a vector but I
> can't seem to figure out how to assign a label to a value if it falls
> between a sequence of numbers.

Using cut() you specify break points rather than setting a range for
recoding.  It is pleasantly easy :)  See the documentation ?cut and
you can also look through some examples using:
example(cut)

Cheers,

Josh


>
> If anyone has input for me I would be very grateful.
>
> Thank you
>
> Will
>
> --
> View this message in context: http://r.789695.n4.nabble.com/convert-wind-direction-from-degrees-to-basic-compass-directions-tp3008773p3008773.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list