更正R中的数据帧

时间:2016-07-28 10:55:33

标签: r

我有一个数据框,其中第二列的某些元素放错了位置。例如:

"15365","JAS ONLINE SERVICES PRIVATE LIMITED"
"15366","KRESS ITALIAN FOOD SPECIALTIES PRIVATE LIMITED"
"15367","SHATAYU CRITICARE HOSPITAL AND RESEARCH CENTER PRI
VATE LIMITED"
"15368","WHITE HEARTS FOODIES PRIVATE LIMITED"
"15369","MAAHI LOGISTICS PRIVATE LIMITED"
...
...

"15376","G S LIFE SKILLS EDUCATION WORLDWIDE PRIVATE LIMITE
D"
"15377","RED LINE LOGISTICS PRIVATE LIMITED"

等等。行15367和15376需要编辑。有没有办法在不手动操作的情况下执行此操作?

1 个答案:

答案 0 :(得分:0)

只需使用quote的{​​{1}}参数即可。假设您在变量read.table中包含字符串,并希望将结果ds存储在data.frame中:

my.df

如果要从结果列中删除换行符,可以使用以下代码,只需将my.df <- read.table(text=ds, sep=",", quote="\"") 替换为要用以及replacement替换换行符的文本,并使用列名称你的V2

data.frame