Re: [R] Reading name-value data

2011-08-01 Thread Hadley Wickham
Yes!  Would you mind filing an issue so I dont forget?
Hadley

On Friday, July 29, 2011, Stavros Macrakis macra...@alum.mit.edu wrote:
 Perfect!  Thanks!
 By the way, I see that, unlike base rbind, it does not work for vectors
and lists:
 rbind(c(a=1),c(b=2)) = matrix(1:2,2,1,dimnames=list(NULL,a))
== as.matrix(data.frame(a=1:2))
 but
  rbind.fill(c(a=1),c(b=2)) = NULL
 Shouldn't it give something like
  matrix(c(1,NA,NA,2),2,2,dimnames=list(NULL,c(a,b)))
 or
  data.frame(a=c(1,NA),b=c(NA,2))
 If, on the other hand, it insists on data.frames as input, it should err
out if give non-data-frames.
 -s

 On Thu, Jul 28, 2011 at 19:30, Hadley Wickham had...@rice.edu wrote:

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

 On Thu, Jul 28, 2011 at 5:23 PM, Stavros Macrakis macra...@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 manipul...@googlegroups.com.
  To unsubscribe from this group, send email to
  manipulatr+unsubscr...@googlegroups.com 
manipulatr%2bunsubscr...@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
 http://had.co.nz/ http://had.co.nz/



-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

[[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.


Re: [R] Reading name-value data

2011-07-29 Thread Stavros Macrakis
Perfect!  Thanks!

By the way, I see that, unlike base rbind, it does not work for vectors and
lists:

rbind(c(a=1),c(b=2)) = matrix(1:2,2,1,dimnames=list(NULL,a))
== as.matrix(data.frame(a=1:2))

but

 rbind.fill(c(a=1),c(b=2)) = NULL

Shouldn't it give something like

 matrix(c(1,NA,NA,2),2,2,dimnames=list(NULL,c(a,b)))
or
 data.frame(a=c(1,NA),b=c(NA,2))

If, on the other hand, it insists on data.frames as input, it should err out
if give non-data-frames.

-s


On Thu, Jul 28, 2011 at 19:30, Hadley Wickham had...@rice.edu wrote:

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

 On Thu, Jul 28, 2011 at 5:23 PM, Stavros Macrakis macra...@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 manipul...@googlegroups.com.
  To unsubscribe from this group, send email to
  manipulatr+unsubscr...@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
 http://had.co.nz/


[[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.


[R] Reading name-value data

2011-07-28 Thread Stavros Macrakis
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.


Re: [R] Reading name-value data

2011-07-28 Thread Hadley Wickham
Use plyr::rbind.fill?   That does match up columns by name.
Hadley

On Thu, Jul 28, 2011 at 5:23 PM, Stavros Macrakis macra...@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 manipul...@googlegroups.com.
 To unsubscribe from this group, send email to
 manipulatr+unsubscr...@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
http://had.co.nz/

__
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.