R: convert variable to csv string

前端 未结 2 819
北海茫月
北海茫月 2021-01-19 15:56

I would like to know how to convert a variable in R to csv string.

> x = c(1:10)
> a = write.csv(x)
\"\",\"x\"
\"1\",1
\"2\",2
\"3\",3
\"4\",4
\"5\",5         


        
2条回答
  •  抹茶落季
    2021-01-19 16:21

    Things can be so simple ....

     > zz <- textConnection("foo1", "w") 
     > textConnectionValue(zz) 
     character(0) 
     > write.csv(x, zz) 
     > textConnectionValue(zz) 
     [1] "\"\",\"x\"" "\"1\",1" "\"2\",2" "\"3\",3" "\"4\",4" 
     [6] "\"5\",5" "\"6\",6" "\"7\",7" "\"8\",8" "\"9\",9" 
     [11] "\"10\",10"
     > 
    

提交回复
热议问题