Re: [R] Parsing variable-length delimited strings into a matrix

2011-10-04 Thread jim holtman
Will this do it for you: > x <- readLines(textConnection("A,B,C + B,B + A,AA,C + A,B,BB,BBB,B,B")) > closeAllConnections() > x.s <- strsplit(x, ',') > # determine max length > x.max <- max(sapply(x.s, length)) > # create character matrix > x.mat <- matrix( + sapply(x.s, function(a) c(a, rep(NA

Re: [R] Parsing variable-length delimited strings into a matrix

2011-10-03 Thread R. Michael Weylandt
Well how do you want it be made into a matrix if the rows are all different lengths? Methinks you are finding this tricky for a reason... Michael On Mon, Oct 3, 2011 at 11:40 AM, Benjamin Wright wrote: > > I'm struggling to find a way of parsing a vector of data in this sort of form: > > A,B,C >

[R] Parsing variable-length delimited strings into a matrix

2011-10-03 Thread Benjamin Wright
I'm struggling to find a way of parsing a vector of data in this sort of form: A,B,C B,B A,AA,C A,B,BB,BBB,B,B into a matrix (or data frame). The catch is that I don't know a priori how many entries there will be in each element, nor how many characters there will be. strsplit(vec,",") gets me