I want to calculate the number of days in each month with rainfall >= 2.5 mm for every column. I was able to calculate it for a single column after taking help from this post like
require(seas)
library (zoo)
data(mscdata)
dat.int <- (mksub(mscdata, id=1108447))
dat.int$yearmon <- as.yearmon(dat.int$date, "%b %y")
require(plyr)
rainydays_by_yearmon <- ddply(dat.int, .(yearmon), summarize, rainy_days=sum(rain >= 1.0) )
print.data.frame(rainydays_by_yearmon)
Now I want to apply it for all the columns. I have tried the following code
for(i in 1:length(dat.int)){
y1 <- dat.int[[i]]
rainydays <- ddply(dat.int, .(yearmon), summarize, rainy_days=sum(y1 >= 2.5))
if(i==1){
m1 <- rainydays
}
else{
m1 <- cbind(rainydays, m1)
}
print(i)
}
m1
But I am unable to get the desired results. Please help me out!!!