Borja .
2013-Mar-20 22:17 UTC
[R] problem subsetting data.frame in R version 2.15.2 for Windows
Good day. I create a data frame like this: > data <- data.frame(a=1:10,b=11:20,c=21:30) I can subset this data.frame by saying: > data[data$a>7,] and I get this result a b c 8 8 18 28 9 9 19 29 10 10 20 30 I understand I should get the same result by saying > data[a>7,0] but I don't. Instead I get: Error in `[.data.frame`(data, a > 7, 0) : object 'a' not found Thank you very much in advance [[alternative HTML version deleted]]
Rui Barradas
2013-Mar-20 23:39 UTC
[R] problem subsetting data.frame in R version 2.15.2 for Windows
Hello, Inline. Em 20-03-2013 22:17, Borja . escreveu:> Good day. > I create a data frame like this: > > data <- data.frame(a=1:10,b=11:20,c=21:30) > I can subset this data.frame by saying: > > data[data$a>7,] > and I get this result > a b c 8 8 18 28 9 9 19 29 10 10 20 30 > I understand I should get the same result by saying > > data[a>7,0] > but I don't.Because what you understand is wrong. There is no object 'a'. The error message is very clear. What you have is an element of the data.frame named 'a', that can be accessed like data$a or data[["a"]]. Use the first way of subsetting the data.frame. Also, 'data' is a bad name for an object, it already is a function name. Hope this helps, Rui Barradas Instead I get:> Error in `[.data.frame`(data, a > 7, 0) : object 'a' not found > Thank you very much in advance > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >
Pierrick Bruneau
2013-Mar-21 07:39 UTC
[R] problem subsetting data.frame in R version 2.15.2 for Windows
Hi Borja, You may issue: attach(data) which results in adding your column names to the search path of R for name resolving. Pierrick Bruneau CRP Gabriel Lippmann On Wed, Mar 20, 2013 at 11:17 PM, Borja . <borjalatorre@outlook.com> wrote:> Good day. > I create a data frame like this: > > data <- data.frame(a=1:10,b=11:20,c=21:30) > I can subset this data.frame by saying: > > data[data$a>7,] > and I get this result > a b c 8 8 18 28 > 9 9 19 29 10 10 20 30 > I understand I should get the same result by saying > > data[a>7,0] > but I don't. Instead I get: > Error in `[.data.frame`(data, a > 7, 0) : object 'a' not > found > Thank you very much in advance > [[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. >[[alternative HTML version deleted]]