I have more than 30 csv files with the same amount of columns and rows and the same name header. I am trying to calculate the mean on one of the columns for each file and putting them into a new file with each of my csv file name and calculated mean. This is how my data looks: data
I have used list files:
estaciones <- list.files(path = "D:/A/",
recursive = T, pattern = "PRCPTOT.csv", full.names = T)
And then I read the csv's using:
estaciones = lapply(estaciones, read.csv)
I also need to change -99-9 values to NA, but the next code line does not seem to be working fine:
lapply(estaciones, function(prcptot) {prcptot[prcptot ==-99.9] <- NA; return(prcptot)})
When I see my data it seems to have made the replacement, but when I try to calculate the mean with the following code, I get NA values for each of my data frames.
apply(estaciones, mean)
How can replace values correctly for all of my files, calculate mean for each data frame and creating a new file with the calculated means for each csv file and respective names? Thank you