regex - Break list into rows while preserving identifiers in r -


i'm working following type of dataset

    names<-c("aname","aname","bname","cname","cname")     list <- list( c('a, b','b, r','c, g'), c('d,g','e,j'),     c('d, h','s, q','f,q'), c('d,r ','s, z'),c('d, r','d, r'))     data<-cbind(names, list) 

and want break out each element of list , bind "name" variable. dataset i'm trying produce this:

column 1   column 2 aname      aname      b aname      b aname      r aname      c 

there have been many discussions of how convert list data.frame, i'm struggling find advice how "within" dataframe i'd preserve identifiers on same row list (in case names). many thanks!

you use melt

library(reshape2) melt(lapply(setnames(list, names), function(x)                       unlist(strsplit(x, ', | |,')))) 

Comments