Error in writing a file from R
1
0
Entering edit mode
6.2 years ago
vinayjrao ▴ 250

Hello,

I have a list in R, which I need to write into a file. When I try running write.table(data, file="molecules.txt"), I get the following error -

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 1, 5, 547

Could someone please help me understand the error and how to go about solving it?

Thanks.

R write.table • 1.7k views
ADD COMMENT
3
Entering edit mode
6.2 years ago
arta ▴ 670

Try write.table(unlist(data), file="molecules.txt")

ADD COMMENT
0
Entering edit mode

That solved the problem. Could you please explain to me what the error was?

ADD REPLY
1
Entering edit mode

You said your input is list, however write.table requires vector, data frame or data table. That is why you get an error (I assume). To write as list you can use write.list function which i have not used so far.

ADD REPLY

Login before adding your answer.

Traffic: 2434 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6