我在R输出中有一些制表符或空格符(我怀疑输出来自哪个任务中的问题),使其看起来像这样:
[1841] "\t\t\tGreen\n\t\t" [1842] "Blue" [1843] "\t\t\tRed\n\t\t"对于一个同事,我必须将它读入SPSS,并且在将它作为txt数据读取时会遇到一些麻烦,所以我想删除字符串中的\ t和\ n部分:
str_replace(mydata, "([\n])", "")试用\ n和\ t或组合,但从未完全奏效。
我的错误在哪里?
I have some tabs or space breaks in my R output (I suspect the problem in the task from which the output comes), making it look like this:
[1841] "\t\t\tGreen\n\t\t" [1842] "Blue" [1843] "\t\t\tRed\n\t\t"For a colleague I have to read this into SPSS and that gives some trouble when reading this as txt data, so I wanted to remove the \t and \n parts in my string:
str_replace(mydata, "([\n])", "")Tried it with both \n and \t or combinations, but never quite worked.
Where is my mistake?
最满意答案
您需要使用str_replace_all删除多个空白字符的帐户。 为什么不使用base R删除这些字符而不是加载stringr包?
gsub('[\t\n]', '', mydata)You need to use str_replace_all to remove the multiple accounts of whitespace characters. Why not use base R to remove these characters instead of loading the stringr package?
gsub('[\t\n]', '', mydata)更多推荐
发布评论