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