[R] Reading name-value data

Hadley Wickham hadley at rice.edu
Fri Jul 29 01:30:34 CEST 2011

Use plyr::rbind.fill?   That does match up columns by name.

On Thu, Jul 28, 2011 at 5:23 PM, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> 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
> --
> You received this message because you are subscribed to the Google Groups
> "manipulatr" group.
> To post to this group, send email to manipulatr at googlegroups.com.
> To unsubscribe from this group, send email to
> manipulatr+unsubscribe at googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/manipulatr?hl=en.

Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University

More information about the R-help mailing list