title: how to use which() in R, if I have too many query conditions?
body: <p>I know, we can use which() function to subset the data frame according to the given condition.If I have a data frame(dat) with 5 columns and I need to find the mean of 5th column of the rows with w,x,y,z as their 1st,2nd,3rd and 4th column ,then I would do as this-</p>
  
  <pre><code> myrows&lt;-dat[which((dat[,1]==w)&amp;(dat[,2]==x)&amp;(dat[,3]==y)&amp;(dat[,4]==z)),5]
   mean(myrows)
  </code></pre>
  
  <p>Now, if there are 50 such columns then I certainly cannot hard-code as this-</p>
  
  <pre><code> myrows&lt;-dat[which((dat[,1]==w)&amp;(dat[,2]==x)&amp;...&amp;(dat[,49]==zz),50]
   mean(myrows)
  </code></pre>
  
  <p>Is there any other way, something like using a for loop like-</p>
  
  <pre><code> for(i in 1:50)
   myrows&lt;-dat[which(dat[,i]==x[i])]
  </code></pre>
  
  <p>I am a beginner in R, so please give an easiest way around this?</p>