Dear all
I have a dataframe containing hourly data of 3 parameters. 
I would like to create a dataframe containg daily mean values of these 
parameters. Additionally I want to keep information about time of 
measurement ("year","month","day"). 
With the function tapply I can average  over a column of the dataframe. 
I can repeat the function 2 time and  merge the vectors. In this way I 
obtain my new dataframe (see below).If I want to add the column day, 
month and year I can repeat tapply other three time. This system works.  


Question: is there a function that average in a single step over the 3 
columns?

Thanks a lot for your answer!
Regards
Mike Campana   

#### read the data
setwd("c:/R")
data <- NULL
data <- as.data.frame(read.table(file="Montreal.txt",header=F,skip=15))
colnames(data) 
<-c("year","month","day","hour","min","temp","press","ozone")
### create  mean value
temp_daily <- 
tapply(data$temp,data$year*10000+data$month*100+data$day,FUN=mean)
press_daily <- 
tapply(data$press,data$year*10000+data$month*100+data$day,FUN=mean)
ozone_daily <- 
tapply(data$ozone,data$year*10000+data$month*100+data$day,FUN=mean)
### merge the data
newdata <- as.data.frame (cbind(temp_daily,temp_daily,temp_daily))

---



---



---



---



---

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to