Skip to content
Prev 326797 / 398502 Next

replace multiple values in vector at once

Hi,
library(car)
?recode(x,"'x'=1;'y'=2;'z'=3")
#[1] 1 1 1 2 2 2 3 3 3
#or
as.numeric(factor(x))
#[1] 1 1 1 2 2 2 3 3 3
A.K.




----- Original Message -----
From: Trevor Davies <davies.trevor at gmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Friday, July 12, 2013 5:56 PM
Subject: Re: [R] replace multiple values in vector at once

I always think that replying to your own r-help feels silly but it's good
to close these things out.

here's my hack solution:

x1<-merge(data.frame(A=x),data.frame(A=c('x','y','z'),B=c(1,2,2)),by='A')[,2]

Well that works and should for my more complex situation.? If anyone has
something a little less heavy handed I'd live to hear it.

Have a great weekend.
On Fri, Jul 12, 2013 at 2:18 PM, Trevor Davies <davies.trevor at gmail.com>wrote:

            
??? [[alternative HTML version deleted]]

______________________________________________
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.