Replace contents of factor column in R dataframe

后端 未结 8 1666
我在风中等你
我在风中等你 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

    I had the same problem. This worked better:

    Identify which level you want to modify: levels(iris$Species)

        "setosa" "versicolor" "virginica" 
    

    So, setosa is the first.

    Then, write this:

         levels(iris$Species)[1] <-"new name"
    

提交回复
热议问题