简体   繁体   English

R中的write.table生成一个空文件

[英]write.table in R generates an empty file

I have a data frame in an object with large number of rows and columns. 我在具有大量行和列的对象中有一个数据框。 I wish to write it in a file, so I do this, 我希望将其写入文件,所以我要这样做,

> write.table(object, file="file.txt")

But I don't know for what reason this is giving me an empty file. 但是我不知道这是什么原因给我一个空文件。 I thought may be because write.table does not handle such large data (800 columns and 450,000 rows). 我认为可能是因为write.table无法处理如此大的数据(800列和450,000行)。 So I tried the following. 因此,我尝试了以下方法。

> write.table(object[1:4,1:5], file="file.txt")

But I still get an empty file. 但是我仍然得到一个空文件。 I checked my object. 我检查了我的物体。 It does contain all the data i need. 它确实包含我需要的所有数据。

Can anyone help me know why I may be getting an empty file? 谁能帮助我知道为什么我会得到一个空文件? Is there any other way to get my object data into a file? 还有其他方法可以将我的对象数据保存到文件中吗?

I am sorry for the trouble, but i just realised what was the problem. 很抱歉给您带来麻烦,但我才意识到问题出在哪里。 I was working with R through a server and it was running out of memory for my data. 我正在通过服务器使用R,但它的内存不足以存储我的数据。 So I deleted a few files and ran the "write.table" command again. 因此,我删除了一些文件,然后再次运行“ write.table”命令。 And now it works fine.. Thank you for your help though.. :) 现在它可以正常工作了。虽然谢谢您的帮助.. :)

I am not sure but you can try to convert your list into a dataframe. 我不确定,但是您可以尝试将列表转换为数据框。 Then you can create a CSV file with your dataframe. 然后,您可以使用数据框创建CSV文件。

df_last<-as.data.frame(do.call(rbind, object))
write.table(df_last, file = "foo.csv", sep = ",")

Try this:- 尝试这个:-

object <- data.frame(a = I("a \" quote"), b = pi)
write.table(object, file = "foo.csv", sep = ",", col.names = NA,
        qmethod = "double")

Do you get foo.csv file created? 您是否创建了foo.csv文件?

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

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