Mehmet Suzen <msuzen <at> mango-solutions.com> writes: > This might be obvious but I was wondering if anyone knows quick and easy > way of writing out a CSV file with varying row lengths, ideally an > initial data read from a CSV file which has the same format. See example > below. > > writeLines(c("A,B,C,D", > "1,a,b,c", > "2,f,g,c", > "3,a,i,j", > "4,a,b,c", > "5,d,e,f", > "6,g,h,i,j,k,l,m,n"), > con=file("test.csv")) >
X <- read.csv("test.csv") It's not that pretty, but something like tmpf <- function(x) paste(x[nzchar(x)],collapse=",") writeLines(apply(as.matrix(X),1,tmpf),con="outfile.csv") might work ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel