阅读 R 中的.CSV
文件后,我之间有很多多余的空格。如何消除这些?
file = read.csv("filename.csv")
读取文件后,我之间有很多空格,如何在 R 中删除?
a = data.frame(Answer = c("who doesn't like some appreciation now and then all employees can give receive non monetary awards in the form of e cards please use the recognition awards and follow instructions there to send an e card want to send some appreciation my way ")
在另一种情况下,我使用下面的代码删除了诸如doesn't
之类的撇号,以便得到doesnt
但得到doesn t
:
a$Answer=gsub('[[:punct:] ]+',' ',a$Answer)
在没有空格的情况下删除撇号的正确方法是什么?
答案 0 :(得分:0)
对于空间问题,我认为 str_squish 可以胜任。它来自软件包 stringr 。 (如果没有,请确保在装入库之前已安装它)
install.packages(stringr)
library(stringr)
a$Answer= str_squish(a$Answer)