s-news
[Top] [All Lists]

[S] Transforming continuous variables

To: s-news@wubios.wustl.edu
Subject: [S] Transforming continuous variables
From: Paul Schwarz <Paul.Schwarz@cornell.edu>
Date: Sun, 26 Apr 1998 23:57:22 -0400
Sender: owner-s-news@wubios.wustl.edu
Transforming variables using a single statement is straightforward.
However, I am baffled about how to transform a continuous variables in
which the transformation depends upon the value of the original variable.
For example, I've been working with slope aspect (again) which is coded in
degrees from 0--360.  I'd like to transform this variable into a range of
values from -90--90 in which 0/360 degrees (North) is transformed to +90,
90 and 270 degrees (E & W) are transformed to 0 and 180 degrees (South) is
transformed to -90.  I couldn't easily think of a one-liner that could do
the transformation in one step, so I started experimenting with ifelse()
statements that divided the range into 90 degree increments e.g., ifelse(
x[ x >= 0 & x <= 90 ], 90-x, ifelse( x[ x > 90 & x <= 180 ], -(x-90), ...
), but that hasn't worked.  The old Fortran programmer in me thinks "loops,
loops" but I know that is not the S way to handle this problem. Could
someone enlighten me a bit?

Many thanks!

-Paul


Paul Schwarz
Department of Natural Resources, Cornell University

Paul.Schwarz@Cornell.EDU
-----------------------------------------------------------------------
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

<Prev in Thread] Current Thread [Next in Thread>