Re: [R] Problem Subsetting Rows that Have NA's

2017-10-25 Thread John
On Tue, 24 Oct 2017 15:05:01 -0400 BooBoo wrote: > This has every appearance of being a bug. If it is not a bug, can > someone tell me what I am asking for when I ask for "x[x[,2]==0,]". > Thanks. > As others have pointed out not a bug, but very "unintuitively" explained in the documentation.

Re: [R] Problem Subsetting Rows that Have NA's

2017-10-25 Thread peter dalgaard
It's not a bug, and the rationale has been hashed over since the beginning of time... It is a bit of an annoyance in some contexts and part of the rationale for the existence of subset(). If you need an explanation, start with elementary vector indexing: colors <- c("red", "green", "blue") col

Re: [R] Problem Subsetting Rows that Have NA's

2017-10-25 Thread David Winsemius
> On Oct 25, 2017, at 11:17 AM, David Winsemius wrote: > > >> On Oct 25, 2017, at 6:57 AM, BooBoo wrote: >> >> On 10/25/2017 4:38 AM, Ista Zahn wrote: >>> On Tue, Oct 24, 2017 at 3:05 PM, BooBoo wrote: This has every appearance of being a bug. If it is not a bug, can someone tell m

Re: [R] Problem Subsetting Rows that Have NA's

2017-10-25 Thread Bert Gunter
... Just to be clear: David's end summary "[" always returns a list. "[[" returns only one thing, but even that thing could be a list. Generally you want "[[" if you plan on testing for equality with a vector. applies to indexing on a **list**, of course, and not to vectors, matrices, etc. Che

Re: [R] Problem Subsetting Rows that Have NA's

2017-10-25 Thread David Winsemius
> On Oct 25, 2017, at 6:57 AM, BooBoo wrote: > > On 10/25/2017 4:38 AM, Ista Zahn wrote: >> On Tue, Oct 24, 2017 at 3:05 PM, BooBoo wrote: >>> This has every appearance of being a bug. If it is not a bug, can someone >>> tell me what I am asking for when I ask for "x[x[,2]==0,]". Thanks. >> You

Re: [R] Problem Subsetting Rows that Have NA's

2017-10-25 Thread BooBoo
On 10/25/2017 4:38 AM, Ista Zahn wrote: On Tue, Oct 24, 2017 at 3:05 PM, BooBoo wrote: This has every appearance of being a bug. If it is not a bug, can someone tell me what I am asking for when I ask for "x[x[,2]==0,]". Thanks. You are asking for elements of x where the second column is equal

Re: [R] Problem Subsetting Rows that Have NA's

2017-10-25 Thread Ista Zahn
On Tue, Oct 24, 2017 at 3:05 PM, BooBoo wrote: > This has every appearance of being a bug. If it is not a bug, can someone > tell me what I am asking for when I ask for "x[x[,2]==0,]". Thanks. You are asking for elements of x where the second column is equal to zero. help("==") and help("[")

Re: [R] Problem Subsetting Rows that Have NA's

2017-10-24 Thread Ek Esawi
z <- x[x[,2]==0&!is.na(x[,2]),] seems to work and get you what you want, but doesn't answer your question, z <- x[x[,2]==0&!is.na(x[,2]),] Best of luck, EK On Tue, Oct 24, 2017 at 3:05 PM, BooBoo wrote: > This has every appearance of being a bug. If it is not a bug, can someone > tell me what

Re: [R] Problem Subsetting Rows that Have NA's

2017-10-24 Thread Ben Tupper
Hi, It's related to how NAs are treated in comparison operations. See the Details section of https://www.rdocumentation.org/packages/base/versions/3.4.1/topics/Comparison You can try something like this... x[whic

[R] Problem Subsetting Rows that Have NA's

2017-10-24 Thread BooBoo
This has every appearance of being a bug. If it is not a bug, can someone tell me what I am asking for when I ask for "x[x[,2]==0,]". Thanks. > #here is the toy dataset > x <- rbind(c(1,1),c(2,2),c(3,3),c(4,0),c(5,0),c(6,NA), + c(7,NA),c(8,NA),c(9,NA),c(10,NA) + ) > x [,1] [,2] [1,]