s-news
[Top] [All Lists]

Re: reversing a scale

To: "Walter R. Paczkowski" <dataanalytics@earthlink.net>
Subject: Re: reversing a scale
From: Chuck Cleland <ccleland@optonline.net>
Date: Fri, 18 Aug 2006 13:33:11 -0400
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <7.0.1.0.2.20060818131329.034347e8@earthlink.net>
References: <7.0.1.0.2.20060818131329.034347e8@earthlink.net>
User-agent: Thunderbird 1.5.0.5 (Windows/20060719)
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

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