Replace contents of factor column in R dataframe

后端 未结 8 1680
我在风中等你
我在风中等你 2020-11-28 20:59

I need to replace the levels of a factor column in a dataframe. Using the iris dataset as an example, how would I replace any cells which contain virginic

8条回答
  •  醉酒成梦
    2020-11-28 21:34

    You can use the function revalue from the package plyr to replace values in a factor vector.

    In your example to replace the factor virginica by setosa:

     data(iris)
     library(plyr)
     revalue(iris$Species, c("virginica" = "setosa")) -> iris$Species
    

提交回复
热议问题