-3

I have a command that I understand:

data$status[which(data$age<18)]<-0

However, I'm just wondering if anyone out there has a nice, neat definition of what which actually is?

I do know, but I'd probably end up coming up with a big flappy definition without being very concise.

Thanks

killahtron
  • 595
  • 1
  • 4
  • 7
  • 8
    Ummm... `?which()`: Give the TRUE indices of a logical object, allowing for array indices – alexwhan Sep 02 '13 at 23:27
  • Thanks. My brain isn't geared into this type of thinking, and I'm a bit tired now. This makes complete sense. Thanks also for reminding me of the help command. – killahtron Sep 02 '13 at 23:32
  • 5
    @killahtron - You've asked 7 questions in 3 days, including 4 in a row which have been downvoted and 2 duplicates. Please search google/s.o. carefully and do a little research before asking another one. – thelatemail Sep 02 '13 at 23:41
  • 1
    http://stackoverflow.com/questions/6918657/whats-the-use-of-which – Ari B. Friedman Sep 02 '13 at 23:42
  • 4
    @killahtron, if you consider a comment which is using `?` a reminder, you really need to read http://cran.r-project.org/doc/manuals/R-intro.html and other introductory documents [here](http://cran.r-project.org/other-docs.html) before asking. If you are tired - sleep. Don't expect others to do basic search for you. – Henrik Sep 02 '13 at 23:49
  • I wasn't aware of how this forum worked, but know the score now. Apologies if I've been a pain in the behind. I've been thrown in the deep end with R over the last few days, and I've been panicking a bit, so perhaps making posts that are a bit silly with hindsight. However, despite all this, everyone has been really, really helpful and I appreciate all the help I've been given. – killahtron Sep 03 '13 at 14:17

1 Answers1

2
 >mydata
                mpg cyl disp  hp
Mazda RX4      21.0   6  160 110
Mazda RX4 Wag  21.0   6  160 110
Datsun 710     22.8   4  108  93
Hornet 4 Drive 21.4   6  258 110

 which(mydata$mpg<22) # shows that rows 1,2,4 of mpg has less than value of 22
[1] 1 2 4

mydata[which(mydata$mpg<22),] # gives the data satisfying the which condition

              mpg cyl disp  hp
Mazda RX4      21.0   6  160 110
Mazda RX4 Wag  21.0   6  160 110
Hornet 4 Drive 21.4   6  258 110
Metrics
  • 15,172
  • 7
  • 54
  • 83