How to export proper TSV?

孤人 提交于 2019-12-05 14:25:35

问题


Short and sweet: how can I export TSV/CSV from R?

write.table / write.csv almost works:

test <- data.frame(a = 2 : 4, b = 3 : 5)
write.table(test, file='test.tsv', quote=FALSE, sep='\t')
$ more test.tsv
a   b
1   2   3
2   3   4
3   4   5

… but produces a format that is different from what’s expected by most other programs:

    a   b
1   2   3
2   3   4
3   4   5

– note the different handling of the header row.

How can I export the second rather than the first format? Manually specifying the col.names as c('', colnames(test)) doesn’t work – R complains about an invalid argument.


回答1:


You can use col.names = NA:

write.table(test, file='test.tsv', quote=FALSE, sep='\t', col.names = NA)



回答2:


you could also consider excluding the row names row.names = FALSE



来源:https://stackoverflow.com/questions/17108191/how-to-export-proper-tsv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!