Skip to content
Prev 284562 / 398502 Next

replace elements of a data frame

names1 price
1    BOO    10
2     CC    25
3    CLR    20

TY for the tip.

Any possibility to write this in one single line?

Arnaud Gaboury
?
A2CT2 Ltd.

-----Original Message-----
From: Berend Hasselman [mailto:bhh at xs4all.nl] 
Sent: mardi 7 f?vrier 2012 20:46
To: Arnaud Gaboury
Cc: Jorge I Velez; r-help at r-project.org
Subject: Re: [R] replace elements of a data frame
On 07-02-2012, at 20:24, Arnaud Gaboury wrote:

            
library(car)

 names<-c("BO","C","CL")
price<-c("10","25","20")
df<-data.frame(names,price)
recode(df$names,"'BO'='BOO'; 'CL'='CLO'; 'C'='CR'")

results in

[1] BOO CR  CLO
Levels: BOO CLO CR

Note the single quotes.

Berend