Add lines to a file

荒凉一梦 提交于 2019-11-26 20:34:12

问题


I'm new using R. I'm trying to add new lines to a file with my existing data in R. The problem is that my data is of about 30000 rows and 13000 cols. I already try to add a line with the writeLines function but the resulted file contains only the line added.


回答1:


Have you tried using the write function?

line="blah text blah blah etc etc"
write(line,file="myfile",append=TRUE)



回答2:


write.table, write.csv and others all have the append= argument, which appends append=TRUE and usually overwrites if append=FALSE. So which one you want to / have to use, depends on your data.

By the way, cat() can also be used to write text to a file and also has the append= argument.




回答3:


lapply(listOfVector, function(anyNameofVect){ write(anyNameofVect, file="outputFileName", sep="\t", append=TRUE, ncolumns=100000) })

or

lapply(listOfVector, write, file="outputFileName", sep="\t", append=TRUE, ncolumns=100000)


来源:https://stackoverflow.com/questions/7741575/add-lines-to-a-file

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