Dear All, Here is a reprex:> x<- 1:100 > x[-which(x>100)]integer(0) In words, I am finding out which indices correspond to values in x which are greater than 100 ( there are no such items ) . Then I remove those indices. I should get back the x that I started with since there are no items in x which are bigger than 100 . Instead, it is returning an empty vector. Why is this ? What am I misunderstanding? Best Regards, Ashim [[alternative HTML version deleted]]
Here's a hint:> y <- which(x>100) > identical(y,y)# TRUE> identical(y,-y)# TRUE The '-' is misleading - it is absorbed into the empty y, leaving the request x[y] to be x for an empty set of indices. HTH, Eric On Wed, Apr 18, 2018 at 2:13 PM, Ashim Kapoor <ashimkapoor at gmail.com> wrote:> Dear All, > > Here is a reprex: > > > x<- 1:100 > > x[-which(x>100)] > integer(0) > > In words, I am finding out which indices correspond to values in x which > are greater than 100 ( there are no such items ) . Then I remove those > indices. I should get back the x that I started with since there are no > items in x which are bigger than 100 . Instead, it is returning an empty > vector. > > Why is this ? What am I misunderstanding? > > Best Regards, > Ashim > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
Look at which(x>100) This is a zero-length vector. The negative of nothing is nothing, not a list of all possible index values. Do you want x[ !( x > 100 ) ] ? On April 18, 2018 6:13:30 AM CDT, Ashim Kapoor <ashimkapoor at gmail.com> wrote:>Dear All, > >Here is a reprex: > >> x<- 1:100 >> x[-which(x>100)] >integer(0) > >In words, I am finding out which indices correspond to values in x >which >are greater than 100 ( there are no such items ) . Then I remove >those >indices. I should get back the x that I started with since there are no >items in x which are bigger than 100 . Instead, it is returning an >empty >vector. > >Why is this ? What am I misunderstanding? > >Best Regards, >Ashim > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.-- Sent from my phone. Please excuse my brevity.
Dear Jeff and Eric, Okay and many thanks. Best Regards, Ashim On Wed, Apr 18, 2018 at 4:56 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> Look at > > which(x>100) > > This is a zero-length vector. The negative of nothing is nothing, not a > list of all possible index values. > > Do you want > > x[ !( x > 100 ) ] > > ? > > On April 18, 2018 6:13:30 AM CDT, Ashim Kapoor <ashimkapoor at gmail.com> > wrote: > >Dear All, > > > >Here is a reprex: > > > >> x<- 1:100 > >> x[-which(x>100)] > >integer(0) > > > >In words, I am finding out which indices correspond to values in x > >which > >are greater than 100 ( there are no such items ) . Then I remove > >those > >indices. I should get back the x that I started with since there are no > >items in x which are bigger than 100 . Instead, it is returning an > >empty > >vector. > > > >Why is this ? What am I misunderstanding? > > > >Best Regards, > >Ashim > > > > [[alternative HTML version deleted]] > > > >______________________________________________ > >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > >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. > > -- > Sent from my phone. Please excuse my brevity. >[[alternative HTML version deleted]]