title: calculate rmse in r using lapply
body: <p>I have small csv files in a directory. I need to calculate rmse and mse from each file.</p>
  
  <p>For example inside Barcelona.csv</p>
  
  <pre><code>City, RealMax, ForecastMax
  Barcelona, 30, 29
  Barcelona, 31, 29
  Barcelona, 32, 31
  Barcelona, 29, 29
  Barcelona, 27, 29
  </code></pre>
  
  <p>I have the next code by now in R</p>
  
  <pre><code>setwd("/home/enric/csv")
  filenames &lt;- list.files(pattern="*.csv", full.names=TRUE)  ###I open all the files csv
  ldf &lt;- lapply(filenames, read.csv, header=FALSE)
  length(ldf)
  ldf
  
  foo &lt;- function(x) {
  # Function that returns Root Mean Squared Error
  rmse &lt;- function(error) {
  sqrt(mean(error^2,na.rm = TRUE))
  }
  
  # Function that returns Mean Absolute Error
  mae &lt;- function(error) {
  mean(abs(error))
  }
  
  error &lt;- x$V2 - x$V3
  mae &lt;- mae(error)  
  rmse &lt;- rmse(error)   
  return( list( mae = mae, rmse = rmse))
  }
  
  res &lt;-lapply(ldf, foo)
  </code></pre>
  
  <p>and I get this message about factors...</p>
  
  <pre><code>&gt; res &lt;-lapply(ldf, foo)
  Warning messages:
  1: In Ops.factor(x$V2, x$V4) : - not meaningful for factors
  2: In Ops.factor(x$V2, x$V4) : - not meaningful for factors
  </code></pre>
  
  <p>How can I convert factor to numerical in order to solve it? Well I think this is the problem, any help?</p>