[R] Calculating a daily average

From: <ecvetano_at_uwaterloo.ca>
Date: Mon, 21 Jun 2010 10:27:18 -0400


I have a set of data with 12 readings for temperature per day, with 180 days. I want to find the average temperature of each day. I am able to do this one by one, but with that many days to calculate the average for, it will get very long. I'm sure there is a faster way to do this, I just don't know how. What i have so far is:

av1 <-  subset(ER9r, Day == 98, select = c (Depth1j:Depth0.75j))
av1 <- mean(av1 [av1>0])
av2 <-  subset(ER9r, Day == 99, select = c (Depth1j:Depth0.75j))
av2 <- mean(av2 [av2>0])
av3 <-  subset(ER9r, Day == 100, select = c (Depth1j:Depth0.75j))
av3 <- mean(av3 [av3>0])
av4 <-  subset(ER9r, Day == 101, select = c (Depth1j:Depth0.75j))
av4 <- mean(av4 [av4>0])
av5 <-  subset(ER9r, Day == 102, select = c (Depth1j:Depth0.75j))
av5 <- mean(av5 [av5>0])

Depth<- c("SML")
Day<- c(98, 99, 100, 101, 102)
Average<- c(av1, av2, av3, av4, av5)
chlsummaryER9 <- data.frame (Depth, Day, Average) chlsummaryER9

Any ideas on how to do this in less steps?

Thanks,
Emilija



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 21 Jun 2010 - 15:21:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jun 2010 - 09:10:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive