title: Subset must be logical error in R
body: <p>I use this code and try to subset it. The source data are below</p>
  
  <pre><code>library(quantmod)
  library(combinat)
  getSymbols("AAPL",from="2012-01-01")
  data&lt;-AAPL
  p1&lt;-4  
  dO&lt;-data[,1]
  dC&lt;-data[,4]
  emaO&lt;-EMA(dO,n=p1)
  emaC&lt;-EMA(dC,n=p1)
  Pos_emaO_dO_UP&lt;-emaO&gt;dO
  Pos_emaO_dO_D&lt;-emaO&lt;dO
  Pos_emaC_dC_UP&lt;-emaC&gt;dC
  Pos_emaC_dC_D&lt;-emaC&lt;dC
  Pos_emaC_dO_D&lt;-emaC&lt;dO
  Pos_emaC_dO_UP&lt;-emaC&gt;dO
  Pos_emaO_dC_UP&lt;-emaO&gt;dC
  Pos_emaO_dC_D&lt;-emaO&lt;dC
      frame&lt;-
  data.frame(Pos_emaO_dO_UP,Pos_emaO_dO_D,Pos_emaC_dC_UP,Pos_emaC_dC_D,Pos_emaC_dO_D,Pos_emaC_dO_UP,Pos_emaO_dC_UP,Pos_emaO_dC_D)
      colnames(frame)&lt;-vector&lt;-c("Pos_emaO_dO_UP","Pos_emaO_dO_D","Pos_emaC_dC_UP","Pos_emaC_dC_D","Pos_emaC_dO_D","Pos_emaC_dO_UP","Pos_emaO_dC_UP","Pos_emaO_dC_D")
  </code></pre>
  
  <p>This is the code was used to take out the nonsense columns</p>
  
  <pre><code>comb&lt;-as.data.frame(combn(vector,4))
  comb
  
  
  rc&lt;-comb[!sapply(comb, function(x) any(duplicated(sub('_D|_UP', '', x))))]
  </code></pre>
  
  <p>And then I've tried to subset the main frame by combination of variables from first column   </p>
  
  <pre><code>kb&lt;-as.vector(rc[,1])
      vr&lt;-paste(kb,collapse=" &amp; ")
      subset(frame,vr)
  </code></pre>
  
  <p>But the result is : subset must be logical. I need to subset the frame by all these combinations like </p>
  
  <pre><code>subset(frame,Pos_emaO_dO_D &amp; Pos_emaC_dC_UP &amp; Pos_emaC_dO_D &amp; Pos_emaO_dC_UP) #etc.
  </code></pre>
  
  <p>one by one a then use on each subset function which I wrote to analyse</p>
  
  <pre><code>subsetit&lt;-function(x,y){
    f&lt;-head(subset(main_table,y &amp; x),-1)
    1d_l_prof&lt;-nrow(f[f$Profit_L_1&gt;0.1,])/nrow(f)
    2d_l_prof&lt;-(nrow(f[f$Profit_L_2&gt;0.1,])/nrow(f))/2
    3d_l_prof&lt;-(nrow(f[f$Profit_L_3&gt;0.1,])/nrow(f))/3
    4d_l_prof&lt;-(nrow(f[f$Profit_L_4&gt;0.1,])/nrow(f))/4
    5d_l_prof&lt;-(nrow(f[f$Profit_L_5&gt;0.1,])/nrow(f))/5
    6d_l_prof&lt;-(nrow(f[f$Profit_L_6&gt;0.1,])/nrow(f))/6
    7d_l_prof&lt;-(nrow(f[f$Profit_L_7&gt;0.1,])/nrow(f))/7
    8d_l_prof&lt;-(nrow(f[f$Profit_L_8&gt;0.1,])/nrow(f))/8
    9d_l_prof&lt;-(nrow(f[f$Profit_L_9&gt;0.1,])/nrow(f))/9
    10d_l_prof&lt;-(nrow(f[f$Profit_L_10&gt;0.1,])/nrow(f))/10
    df&lt;-data.frame(1d_l_prof,2d_l_prof,3d_l_prof,4d_l_prof,5d_l_prof,6d_l_prof,7d_l_prof,8d_l_prof,9d_l_prof,10d_l_prof)
    return(df)
  }
  </code></pre>
  
  <p>Where should be the problem of subset error? 
  Will works some </p>
  
  <pre><code>lapply(rc[,c(1:length(rc))],subsetit] ?
  </code></pre>