Re: [S] Recoding slope aspect values

Jens Oehlschlaegel (oehl@Psyres-Stuttgart.DE)
Wed, 8 Apr 1998 19:30:28 +0200 (MET DST)


The cut task can be done with the following function cut.degree().

functions and example follow
Best regards

Jens Oehlschlaegel

cut.degrees <- function(d, start.d=-45, breaks=4, max.d=360){
# (c) JOA 1998
# expects d element of [-max.d, max.d]
# maps d onto (start.d, start.d+max.d]
# if breaks>0 cuts into breaks intervals
# (c) JOA 1998
if (start.d<0){
id <-
ifelse(d<=start.d,d+max.d,ifelse(d>start.d+max.d,d-max.d,d))
}else{
id <-
ifelse(d<=start.d-max.d,d+2*max.d,ifelse(d<=start.d,d+max.d,d))
}
if (breaks>0) cut( id, seq(0,360,360/breaks)+start.d ,
include.lowest=T)
else id
}

xy.degrees <- function(d, max.d=360){
id <- 2*pi*d/max.d
x <- cos(id)
y <- sin(id)
list(x=x,y=y)
}

#example
compass <- c("E","N","W","S")
d <- seq(0,360,11.25)
cbind(d=d,cut=cut.degrees(d),as.data.frame(xy.degrees(d)))
plot(c(-1.5,1.5),c(-1.5,1.5), type="n")
text(xy.degrees(d),compass[cut.degrees(d)])

On Wed, 8 Apr 1998, Paul Schwarz wrote:

> Hello,
>
> I have a data set that contains slope aspect (azimuth) measure in degrees
> (0--360). I would like to recode this variable into compass directions
> (N,S,E,W, etc.) for use in plotting and analysis. I know that I can use
> cut/cut2 to do this, but this a bit problematic because I want to divide
> continuous vector into 4 intervals coded as follows:
>
> N : 315 -- 45 degrees
> E : 45 -- 135
> S : 135 -- 225
> W : 225 -- 315
>
> So the only way I know how to do this is create 5 intervals and recode the
> 5th interval back to the 1st interval -- sort of clumsy. I'd also like to
> be able to create directly the categories as 'N', 'E', 'S', 'W' rather than
> 1, 2, 3, 4. Does anyone know of an "elegant" way to do this recoding?
>
> On a related topic, I am also looking for a way to preserve the continuous
> nature of slope aspect for use in regression analysis rather than resorting
> to a categorical representation. Does anyone have any clever suggestions
> on how I might do this given that 359 degrees and 1 degrees are both
> basically North?
>
> Many thanks!
>
> -Paul
> Paul.Schwarz@Cornell.EDU
>
> P.S. I'm in the process of re-subscribing to s-news, so I would appreciate
> it if those of you with suggestions could cc: me directly because it may
> take a day or two to get my subscription set up.
> -----------------------------------------------------------------------
> This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
> send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
> message: unsubscribe s-news
>

--
Jens Oehlschlaegel-Akiyoshi
Psychologist/Statistician
Project TR-EAT + COST Action B6
                                                 F.rankfurt
oehl@psyres-stuttgart.de                         A.ttention
+49 711 6781-408 (phone)                         I.nventory
+49 711 6876902  (fax)                           R .-----.
                                                  / ----- \
Center for Psychotherapy Research                | | 0 0 | |
Christian-Belser-Strasse 79a                     | |  ?  | |
D-70597 Stuttgart Germany                         \ ----- /
-------------------------------------------------- '-----' -
(general disclaimer)                             it's better

----------------------------------------------------------------------- This message was distributed by s-news@wubios.wustl.edu. To unsubscribe send e-mail to s-news-request@wubios.wustl.edu with the BODY of the message: unsubscribe s-news