I have a file of data where each line is a series of name-value pairs, but
where the names are not necessarily the same from line to line, e.g.

   a=1,b=2,d=5
   b=4,c=3,e=3
   a=5,d=1

I would like to create a data frame which lines up the data in the
corresponding columns.  In this case, this would be

   data.frame( a = (1, NA, 4), b = (2, 4, NA), c = (NA, 3, NA), d = (5, NA,
1), e = (NA, 3, 1) )

One way I can think of doing this is to read in the data as one 'long' data
frame per line with a unique ID, e.g. line one becomes

     cbind(id=1,data.frame(variable=c('a','b','d'),value=c(1,2,5)))

then rbind all the lines and use the reshape package function 'cast'.

Is there a more straightforward way?  (I'd have thought rbind would line up
columns by name, but it doesn't.)

            -s

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to