[R] Deleting colmuns with 0's and also writing multple csv files

RICHARD M. HEIBERGER rmh at temple.edu
Fri Feb 19 08:06:41 CET 2010


> (2)  Suppose I have variable no of datasets 'say n = 10'. I wish to write a loop assigning each of these datasets to diffrent csv files e.g.
>
> for (i in 1:10)
>  {
> write.csv(data.frame(dataset[,,i]), 'data_set[i].csv', row.names = FALSE)
>  }
>
> The result of this command is generation of a csv file 'data_set[i].csv' containing the last dataset (owing to the wrong command written by me).
>
> What I need is creation of say data_set[1].csv, data_set[2].csv,  .........data_set[10].csv i.e. 10 different csv files containing 10 different datasets.


Why do you want to create csv datasets?  They lose much of the
structure that is in the R object.
If you are trying to transfer them to somewhere else, then a direct
transfer would be a better choice.

If the goal is Excel, there are about 5 options.  I prefer RExcel
because it allows the tightest
coordination of the R and the Excel calculations.

If the goal is one of the other popular statistical systems, they also
have direct connections,
often through the foreign package.

Rich



More information about the R-help mailing list