Skip to content
Prev 351118 / 398502 Next

apply a function to a list of data frames

Hello,

You should change your function to accept only one argument, the 
data.frames, and then use lapply (not sapply).
Something like the following.

calc <- function(dat)
{
	bias_dmo_max <- round(mean((dat$dmo_12-dat$Eonestep_12), na.rm=TRUE), 
digits=2)
	rmse_dmo_max <- round(sqrt(mean((dat$dmo_12-dat$Eonestep_12)^2, 
na.rm=TRUE)), digits=2)
	bias_dmo_min <- round(mean((dat$dmo_27-dat$Eonestep_27), na.rm=TRUE), 
digits=2)
	rmse_dmo_min <- round(sqrt(mean((dat$dmo_27-dat$Eonestep_27)^2, 
na.rm=TRUE)), digits=2)
	result <- list(bias_dmo_max, rmse_dmo_max, bias_dmo_min, rmse_dmo_min)
	result
}

result_lst <- lapply(lst, calc)


Hope this helps,

Rui Barradas


Em 22-05-2015 19:02, Stefano Sofia escreveu: