[R] Regular repeats

Doran, Harold HDoran at air.org
Tue Aug 13 21:05:45 CEST 2013


What about something like this:

tmp <- data.frame(var1 = rnorm(36), ind = gl(6,6))

with(tmp, tapply(var1, ind, mean))

You can see that your version of

mean(tmp[1:6,c("var1")])

gives the same as mine for the first 6 rows.


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of jsf1982
Sent: Tuesday, August 13, 2013 12:46 PM
To: r-help at r-project.org
Subject: [R] Regular repeats

Hi,
Many apologies for the simplicity (hopefully!) of this request - I can't find it on the forum, but it may have been asked in the past.

I have a data frame consisting of ~2000 rows. I simply want to take the average of the first 6, then the next 6, then the next 6 until the end of the table. 
The command 

mean(mole[1:6,c("PercentPI")])

gets me the first 6 rows (column is PercentPI), but I don't know how to increase the rows incrementally.

Thanks in advance.
J





--
View this message in context: http://r.789695.n4.nabble.com/Regular-repeats-tp4673653.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.



More information about the R-help mailing list