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
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
>
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
3 matches
Mail list logo