Whitespace string can't be replaced with NA in R

前端 未结 2 1397
刺人心
刺人心 2021-01-15 00:13

I want to substitute whitespaces with NA. A simple way could be df[df == \"\"] <- NA, and that works for most of the cells of my data frame....but not for ev

2条回答
  •  一整个雨季
    2021-01-15 00:56

    I just spent some time trying to determine a method usable in a pipe.

    Here is my method:

    df <- df %>% 
        dplyr::mutate_all(funs(sub("^\\s*$", NA, .)))
    

    Hope this helps the next searcher.

提交回复
热议问题