An embedded and charset-unspecified text was scrubbed... Name: no disponible URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130320/e008f21a/attachment.pl>
problem subsetting data.frame in R version 2.15.2 for Windows
7 messages · Borja ., Rui Barradas, Pierrick Bruneau +3 more
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130321/5e5a0ae3/attachment.pl>
On Mar 21, 2013, at 7:39, Pierrick Bruneau <pbruneau at gmail.com> wrote:
Hi Borja, You may issue: attach(data)
No -- bad idea -- dangerous -- confusing statefulness, etc. (See explanations in the archives as to why)
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 at 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
Try instead with(dat, dat[a > 0, ]) for a cleaner option. MW
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.
[[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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130321/41ef4e6b/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130321/333b1001/attachment.pl>
Hi in interactive sessions it is convenient way to call data frame columns and repeatedly use them in calculations. You just have to be careful with some functions as they can be useful but dangerous. rm(something) removes an object from environment without warning. It is usually not a fault of a program, when something gets wrong. Regards Petr
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of Pierrick Bruneau Sent: Thursday, March 21, 2013 9:13 AM To: Michael Weylandt Cc: r-help at r-project.org Subject: Re: [R] problem subsetting data.frame in R version 2.15.2 for Windows OK, I just had a look at the Good Practice section of ?attach, it indeed looks bad... Maybe this danger should be emphasized in ?attach, or the function even deprecated (why maintaining ugly patterns when better solutions exist?) On Thu, Mar 21, 2013 at 8:58 AM, Michael Weylandt < michael.weylandt at gmail.com> wrote:
On Mar 21, 2013, at 7:39, Pierrick Bruneau <pbruneau at gmail.com>
wrote:
Hi Borja, You may issue: attach(data)
No -- bad idea -- dangerous -- confusing statefulness, etc. (See explanations in the archives as to why)
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 at 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
Try instead with(dat, dat[a > 0, ]) for a cleaner option. MW
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.
[[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.
[[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.