使用dplyr去除R列值中的空格

使用dplyr去除R列值中的空格,r,dplyr,R,Dplyr,我有一些列出邮政编码的数据: Postcode easting northing 1 AB1 1AA 394251 806376 2 AB1 1AB 394235 806529 3 AB1 1AF 394181 806429 4 AB1 1AG 394251 806376 5 AB1 1AH 394371 806359 我希望通过执行以下操作来清除“邮政编码”列中的所有空格: library(dplyr) postcodes %>% muta

我有一些列出邮政编码的数据:

   Postcode easting northing
1  AB1 1AA  394251   806376
2  AB1 1AB  394235   806529
3  AB1 1AF  394181   806429
4  AB1 1AG  394251   806376
5  AB1 1AH  394371   806359
我希望通过执行以下操作来清除“邮政编码”列中的所有空格:

library(dplyr)
postcodes %>% mutate(Postcode = gsub(" ", "", Postcode))
但是它在我的data.frame上似乎不起作用。知道我哪里出错了吗

我可以通过以下方式在base R中实现:

  postcodes$Postcode <- gsub(" ", "", postcodes$Postcode)

postcodes$Postcode您的代码可以为我找到。请记住,这些dplyr函数返回新的数据帧,它们不会重新写入旧的数据帧。您确定它不适合您吗?如果您想在执行时更改,请尝试从
magrittr
更改
%%
,即
postcodes%%mutate(Postcode=gsub(“”,,,Postcode))
ah,可能就是这样!很抱歉,邮政编码%mutate(Postcode=gsub(“,”,Postcode))您想添加它作为答案吗,我会勾选它