Replace all NA with FALSE in selected columns in R

前端 未结 5 1825
挽巷
挽巷 2020-12-31 01:57

I have a question similar to this one, but my dataset is a bit bigger: 50 columns with 1 column as UID and other columns carrying either TRUE or NA

5条回答
  •  猫巷女王i
    2020-12-31 02:50

    With dplyr you could also do

    df %>% mutate_each(funs(replace(., is.na(.), F)), x1, x2)
    

    It is a bit less readable compared to just using replace() but more generic as it allows to select the columns to be transformed. This solution especially applies if you want to keep NAs in some columns but want to get rid of NAs in others.

提交回复
热议问题