[R] apply a function to a list of data frames

Stefano Sofia stefano.sofia at regione.marche.it
Fri May 22 20:02:26 CEST 2015


Dear R-users,
given a list of dataframes (like below reported), for each month I need to apply a function (called calc).
The result should be written in a new list of data frames, one row for each month.

I have been trying to use sapply, with no success.
Could somebody help me in this?


$df1
day dmo_12 Eonestep_12 tmax dmo_27 Eonestep_27 tmin
2012-12-01 11 13 13 9 8 8
2012-12-02 11 13 13 5 6 8
2012-12-03 6 10 8 6 6 7
2012-12-04 11 13 9 6 6 3
2012-12-05 8 10 12 5 6 7
2012-12-06 8 10 8 4 5 4
2012-12-07 7 9 8 6 6 5
...


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


Thank you for your help
Stefano


________________________________

AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.

	[[alternative HTML version deleted]]



More information about the R-help mailing list