Add extra level to factors in dataframe

后端 未结 5 1255
时光取名叫无心
时光取名叫无心 2020-11-30 04:09

I have a data frame with numeric and ordered factor columns. I have lot of NA values, so no level is assigned to them. I changed NA to \"No Answer\", but levels of the facto

5条回答
  •  情歌与酒
    2020-11-30 04:32

    I have a very simple answer that may not directly address your specific scenario, but is a simple way to do this generally

    levels(df$column) <- c(levels(df$column), newFactorLevel)
    

提交回复
热议问题