繁体   English   中英

将数据帧写入以分号分隔的CSV,其中列数据包含分号?

[英]Writing data frame to semicolon-delimited CSV where column data contains semi-colon?

如何写入以下数据完整的CSV? 我想将此数据写入带有分隔符作为分号的CSV文件中,但是第二行由于分号而移位。

我有一个包含以下数据的数据框:

             a <- c(1,2,3,4)
             b <- c("hello","hello;world","hey","there")
             c <- c(10,20,30,40)
             df <- data.frame(a,b,c)
             df
             df
               a           b  c
             1 1       hello 10
             2 2 hello;world 20
             3 3         hey 30
             4 4       there 40

引用输出:

a<-c(1,2,3,4)
b<-c("hello","hello;world","hey","there")
c<-c(10,20,30,40)
df<-data.frame(a,b,c)
write.table(df, file="blah.csv",quote=TRUE, sep = ";")

"a";"b";"c"
"1";1;"hello";10
"2";2;"hello;world";20
"3";3;"hey";30
"4";4;"there";40

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM