简体   繁体   中英

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). 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. So I deleted a few files and ran the "write.table" command again. 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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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