[问题] 对一个dataframe里的column做替换

楼主: alasa15 (alasa)   2015-04-02 19:10:13
我现在造一个data frame z
x <- c(3,2,3,2,3,1,1,2)
y <- 1:8
z <- as.data.frame(cbind(x,y))
对这个data frame z
请问有没有不用loop的方法把column x里面的 1 2 3 替换成 'a' 'b' 'c' 呢?
谢谢
作者: ntme (one shot one kill)   2015-04-02 19:27:00
z$x[z$x == 1] = "a"
作者: ty854697   2015-04-02 22:27:00
try mapvalues() or revalue()http://ppt.cc/ZNeJ

Links booklink

Contact Us: admin [ a t ] ucptt.com