title: calculating length using na.omit in R
body: <p>here is my code:</p>
  
  <pre><code>data &lt;-setNames(lapply(paste0("80-20 ", file.number,".csv"),read.csv,stringsAsFactors=FALSE),paste(file.number,"participant"))
  # imports csv data and turns it into a R-data file
  
  df &lt;- data.frame(RT=1:100,rep.sw=sample(c("sw","rep",100,replace=TRUE)))
  
  (error.sw.c &lt;- lapply(data[control.data],function(df) with(df, na.omit(rep.sw == "sw" &amp; accuracy == "wrong"))))
  </code></pre>
  
  <p>This code scans a bunch of excel file and attributes a value of 'TRUE' every time the accuracy is "wrong" for values labeled "sw." then what I want to do is count the number of true values, and put them in a data frame. This is what I tried: </p>
  
  <pre><code>(dataframe.c &lt;- data.frame(switch.rt = sapply(sw.c,mean), repetition.rt = sapply(rep.c,mean), switch.error = sapply(error.sw.c,length), group = rep("control",each=length(control.data))))
  </code></pre>
  
  <p>However, when I do this, it gives me the length of all the values (TRUE &amp; FALSE), not just the TRUE values. </p>
  
  <p>If I do this: </p>
  
  <pre><code>length(error.sw.c)
  </code></pre>
  
  <p>I get the total of all the error values, not all the error values separately.  </p>
  
  <p>So my question is: Is there a way to get the length of each individual excel file so I can put it in a dataframe? Thank you StackOverflow community, you folks haven't let me down yet. Any help will be greatly appreciated. Let me know if any clarification is needed. :)</p>