Replace all occurrences of a string in a data frame

后端 未结 6 695
面向向阳花
面向向阳花 2020-11-27 02:54

I\'m working on a data frame that has non-detects which are coded with \'<\'. Sometimes there is a space after the \'<\' and sometimes not e.g. \'<2\' or \'< 2\

6条回答
  •  情歌与酒
    2020-11-27 03:30

    To remove all spaces in every column, you can use

    data[] <- lapply(data, gsub, pattern = " ", replacement = "", fixed = TRUE)
    

    or to constrict this to just the second and third columns (i.e. every column except the first),

    data[-1] <- lapply(data[-1], gsub, pattern = " ", replacement = "", fixed = TRUE)
    

提交回复
热议问题