Re: [Rd] read.csv behaviour

From: Ben Bolker <bbolker_at_gmail.com>
Date: Wed, 28 Sep 2011 12:19:22 +0000

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_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 28 Sep 2011 - 12:25:11 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 29 Sep 2011 - 11:20:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive