This is my data:
ens1 <- read.csv("G:/ABV_DATA/ABV_2/book3.csv", header=TRUE, sep=",", stringsAsFactors = FALSE)
attach(ens1)
dates = as.Date(ens1$date, "%m/%d/%y")
#write.csv(dates, file = "myfile.csv")
ens1 = ens1[,2:4] #remove column 1 and kip columns 2 to 4
ens1 = data.frame(date=dates, ens1)
month.year <- function (x) {12*(as.POSIXlt(x)$year-1)+as.POSIXlt(x)$mon+1}
month = month.year(ens1$date) #the one that works is to use the full ens1$date
mean.TREFHT_MAX = tapply(TREFHT_MAX, month, mean)
sd.TREFHT_MAX= tapply(TREFHT_MAX,month,sd)
mean.RH=tapply(RH,month,mean)
sd.RH=tapply(RH, month,sd)
month = month.name #names from jan or dec
for(i in 1:length(mean.TREFHT_MAX)) {month.observed[i]=as.numeric(names(mean.TREFHT_MAX[i]))%%12
} #first get the months as numbers 0-11
month.observed[month.observed==0]<-12 # make the decembers 12 instead of 0
month.names <- months[as.numeric(month.observed)]
stats <- data.frame(mean.TREFHT_MAX,sd.TREFHT_MAX,mean.RH,sd.RH,month=month.names)
print(stats,digits=3)