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
iris
virginic
You can use the function revalue from the package plyr to replace values in a factor vector.
revalue
plyr
In your example to replace the factor virginica by setosa:
virginica
setosa
data(iris) library(plyr) revalue(iris$Species, c("virginica" = "setosa")) -> iris$Species