2016-07-28 89 views
0

我有一個數據幀,其中第二列的一些元素放錯位置。例如:更正數據幀在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行需要編輯。有沒有辦法做到這一點,而不需要手動進行?

回答

0

只需使用read.tablequote參數即可。假設你有變量ds字符串,並希望存儲所產生的data.framemy.df

my.df <- read.table(text=ds, sep=",", quote="\"") 

如果你想從結果列,你可以使用下面的代碼刪除換行符,只是替換replacement您想要將換行符替換爲V2,並將其列名爲data.frame

my.df$V2 <- gsub("\\n", replacement, my.df$V2)