r - for the length of each row in column Y duplicate row in column X -
(please feel free adjust title more fitting)
i have data.frame
2 columns, x
, y
of class list
below
x <- list("a","b","c","d") y <- list("a",c("a", "b"),"c",c("a", "c", "d")) df <- as.data.frame(cbind(x,y))
when column y
has 2 or more entries or here characters, length of each row in y
(number of characters) correspond number of identical rows in column x
. easier put, each character in y
must individual row in x
.
# desired output x y a b b b c c d d c d d
im not sure how go this, pointers appreciated, thanks!
try
do.call(rbind, map(expand.grid, x, y)) ## var1 var2 ## 1 ## 2 b ## 3 b b ## 4 c c ## 5 d ## 6 d c ## 7 d d
Comments
Post a Comment