R how to change one of the level to NA

前端 未结 4 696
别跟我提以往
别跟我提以往 2021-01-01 16:20

I have a data set and one of its column has factor levels \"a\" \"b\" \"c\" \"NotPerformed\". How can I change all the \"NotPerformed\" factors to

4条回答
  •  没有蜡笔的小新
    2021-01-01 16:59

    Or simply use the inbuilt exclude option, which works regardless of whether the initial variable is a character or factor.

    x <- c("a", "b", "c", "NotPerformed")
    
    factor(x, exclude = "NotPerformed")
    [1] a    b    c    
    Levels: a b c
    
    factor(factor(x), exclude = "NotPerformed")
    [1] a    b    c    
    Levels: a b c
    

提交回复
热议问题