Skip to content

Parsing variable-length delimited strings into a matrix

3 messages · Benjamin Wright, R. Michael Weylandt, jim holtman

#
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 <bjw78 at well.ox.ac.uk> wrote:
#
Will this do it for you:
+ B,B
+ A,AA,C
+ A,B,BB,BBB,B,B"))
+     sapply(x.s, function(a) c(a, rep(NA, x.max - length(a))))
+     , byrow = TRUE
+     , ncol = x.max
+     )
[,1] [,2] [,3] [,4]  [,5] [,6]
[1,] "A"  "B"  "C"  NA    NA   NA
[2,] "B"  "B"  NA   NA    NA   NA
[3,] "A"  "AA" "C"  NA    NA   NA
[4,] "A"  "B"  "BB" "BBB" "B"  "B"

        
On Mon, Oct 3, 2011 at 11:40 AM, Benjamin Wright <bjw78 at well.ox.ac.uk> wrote: