[R] replace elements of a data frame

Arnaud Gaboury arnaud.gaboury at a2ct2.com
Tue Feb 7 19:05:35 CET 2012


I am getting mad at finding a simple way to replace elements of a df.

Here is a short df :

> names<-c("BO","C","CL")
> price<-c("10","25","20")
> df<-data.frame(names,price)

I want to replace "BO" by "BOB", "C" by "CR", "CL" by "CLO", and the list is more long. 
I can do that for each element:


But my df is bigger indeed with other elements.

I was thinking using replace(), but can't get any clean result ( NA or all elements replaced with only one), neither with sapply().

TY for any help, and sorry for the n00b question.

Arnaud Gaboury
A2CT2 Ltd.

More information about the R-help mailing list