Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write.csv() a list of unequally sized data.frames

Tags:

r

I would like to pump out a list of data.frame() objects to a csv file so I can work on it for presentation. I'm finding that it's replying with an error:

In write.csv(tmp[i], file = "Output.csv", append = T) :
  attempt to set 'append' ignored

I've saved the outputs to a list (all of which can be coerced to a df), here's an example:

outputs <- list() 
outputs$fivenum <- fivenum(rnorm(100))
outputs$summary <- as.data.frame(as.vector(summary(rnorm(100))))

tmp <- lapply(outputs, as.data.frame)

write.csv(tmp, file="Output.csv",append=T)

Does every append action have to have the same number of columns?

like image 330
Brandon Bertelsen Avatar asked Sep 08 '11 15:09

Brandon Bertelsen


People also ask

Can you have a list of data frames?

To create a list of Dataframes we use the list() function in R and then pass each of the data frame you have created as arguments to the function.

Is csv file a data frame?

CSV files are the “comma-separated values”, these values are separated by commas, this file can be viewed like an excel file. In Python, Pandas is the most important library coming to data science.

How do I create a Dataframe with different number of rows in R?

To create a data frame of unequal length, we add the NA value at the end of the columns which are smaller in the lengths and makes them equal to the column which has the maximum length among all and with this process all the length becomes equal and the user is able to process operations on that data frame in R ...

What is CSV in R?

R CSV Files. A Comma-Separated Values (CSV) file is a plain text file which contains a list of data. These files are often used for the exchange of data between different applications. For example, databases and contact managers mostly support CSV files.


1 Answers

That's a warning, not an error. You can't change append=FALSE with write.csv. ?write.csv says:

Attempts to change ‘append’, ‘col.names’, ‘sep’, ‘dec’ or ‘qmethod’ are ignored, with a warning.

Use write.table with sep="," instead.

like image 151
Joshua Ulrich Avatar answered Sep 27 '22 23:09

Joshua Ulrich