R: sink() split table in some lines

2019-03-06 12:52发布

问题:

I have a very very big table of correlation values that i would like to save in a file.

That actually do:

sink("/to/path/file.csv")
cor(total)
sink()

that writes something like in the file:

               a          b             c            d
r             0.635391844  0.316249555    0.715476998  0.138705124
y             1.000000000  0.245008313    0.927208342  0.109602263
z             0.245008313  1.000000000    0.239142304  0.080837639
t             0.927208342  0.239142304    1.000000000  0.131402452
h             0.109602263  0.080837639    0.131402452  1.000000000
e             0.996816365  0.247379819    0.930169663  0.108444557
a             0.125584355  0.149714007    0.139603217  0.664041704
a             0.245518153  0.318763442    0.252738479  0.337095547
h                NA           NA             NA           NA
h             0.016062787  0.006800213    0.012608729 -0.024936870


                e              f            g                       h  
a          -0.0671507332 -0.054941719 -0.081309861                 NA
a          -0.0088907191 -0.005160978 -0.024992979                 NA
a          -0.0136534885 -0.037814849 -0.050713280                 NA
a          -0.0045957748 -0.022862111 -0.044030999                 NA
a          -0.0097176798 -0.046629114 -0.106266022                 NA

i would like that columns a,c,d,f,g,h ... where in the same line. I have try also sink("path", split = T), but it doesn't work,

Suggestions?

Thanks.

Carlos

回答1:

Something like this for example:

m <- cbind(read.csv("/to/path/file.csv", cor(total))
write.csv(m,"/to/path/file.csv")


标签: r sink