Split a column by delimiter and replicate the related rows in R
With this data
foo 5 49 10
bar 1,2 22 11
I'd like to split the row by second column, such that the final output gives:
foo 5 49 10
bar 1 22 11
bar 2 22 11
I tried colsplit but not quite there yet:
lines <- "
foo 5 49 10
bar 1,2 22 11"
con <- textConnection(lines)
dat<-read.table(con)
colsplit(t$V2,",",c("F1","F2","F3","F4"))
How this can be done correctly?
No comments:
Post a Comment