xinlee883 at stat.math.ethz.ch
2009-Feb-10 10:25 UTC
[Rd] Bug in subsetting data frame (PR#13515)
Full_Name: Xin Lee Version: 2.8.0 OS: Windows XP Submission from: (NULL) (193.200.150.23) Dear developer I discover annoying bug in subsetting data frame. Here is reproducable examples:> data.frame <- data.frame(x = runif(5), y = runif(5), row.names c('a','b','c','d','e')> subset <- data.frame['x'] > subset['a',]work> subset <- data.frame$x > subset['a',]not work> subset <- data.frame['a',] > subset[,'x']work> subset <- data.frame[,'x'] > subset['a',]not work I hope this is easy fix for you and works corectly soon. Sincerely, Xin Lee
On Tue, 10 Feb 2009 xinlee883 at stat.math.ethz.ch wrote:> > I discover annoying bug in subsetting data frame. Here is reproducable > examples:These are not bugs.>> data.frame <- data.frame(x = runif(5), y = runif(5), row.names > c('a','b','c','d','e') > >> subset <- data.frame['x'] >> subset['a',] > work > >> subset <- data.frame$x >> subset['a',] > not workThis can't possibly work, since you have explicitly requested that subset not be a data frame. There has been recent discussion about whether row names should be added as names to vectors from a data frame, in which case subset['a'] would then work. It doesn't now, and that isn't a bug either.>> subset <- data.frame['a',] >> subset[,'x'] > work > >> subset <- data.frame[,'x'] >> subset['a',] > not workThis is also not a bug. The drop= option to [ controls what happens when the subset has dimensions of length 1. If you want subset to be a data frame in this context, use subset <- data.frame[,'x',drop=FALSE] and then subset['a',] will do want you want. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
Don't know if this is the problem, but.... It is a bad idea to set data.frame <- xxx since R has a single namespace for functions and variables. -s On 2/10/09, xinlee883 at stat.math.ethz.ch <xinlee883 at stat.math.ethz.ch> wrote:> Full_Name: Xin Lee > Version: 2.8.0 > OS: Windows XP > Submission from: (NULL) (193.200.150.23) > > > Dear developer > > I discover annoying bug in subsetting data frame. Here is reproducable > examples: > >> data.frame <- data.frame(x = runif(5), y = runif(5), row.names > c('a','b','c','d','e') > >> subset <- data.frame['x'] >> subset['a',] > work > >> subset <- data.frame$x >> subset['a',] > not work > >> subset <- data.frame['a',] >> subset[,'x'] > work > >> subset <- data.frame[,'x'] >> subset['a',] > not work > > I hope this is easy fix for you and works corectly soon. > > Sincerely, > Xin Lee > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >