[R] writing matrices of different rows in a file

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Jul 8 14:27:55 CEST 2014



On 07.07.2014 10:05, carol white wrote:
> Hi,
> What is the best way of writing of matrices of different rows in a file? Should the matrices with the same number of rows be written first and then, empty columns for the matrices with a smaller number of rows followed by the matrices with a larger number of rows? Not a good solution (see below).
>
> Can't they be written with 1 script?
>
> m = rbind(c(1,2),c(2,44))
> n = rbind(c(1,3),c(2,4),c(5,8))
>
> write.csv(cbind(m,n),...)
> Error in .Method(..., deparse.level = deparse.level) :
>    number of rows of matrices must match (see arg 2)
>
>
> write.csv(cbind(m,n[1.2,]),...)
>   write.csv(cbind(cbind(rep(" ",1), rep(" ",1)),n[3,]),...)
>
> Warning message:
> In write.csv(cbind(cbind(rep(" ", 1), rep(" ", 1)), n[3,  :
>    attempt to set 'append' ignored


First combine them into one matrix, e.g. with missing values, then write...


Best,
Uwe Ligges


>
> Thanks
>
> Carol
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list