Walter R. Paczkowski wrote:
> Hi,
>
> I'm looking for a simple way to convert a scale such as 1, 2, 3, 4, 5 to
> 5, 4, 3, 2, 1. In other words, I want to map
>
> 1 --> 5
> 2 --> 4
> 3 --> 3
> 4 --> 2
> 5 --> 1
>
> So if I have a vector (5, 1, 3, 4, 2, 1, 1, 5), I want to map it to a
> new vector (1, 5, 3, 2, 4, 5, 5, 1). I've been using ifelse statements
> which works but if my scale is, say, 1:100, then I have 100 nested
> statements - that's not good. Any suggestions?
How about this?
X1 <- sample(1:5, 10, replace=TRUE)
X2 <- sample(1:100, 10, replace=TRUE)
X1rev <- 6 - X1
X2rev <- 101 - X2
> Thanks,
>
> Walt Paczkowski
>
> _________________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> (V) 609-936-8999
> (F) 609-936-3733
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
|