# need zoo to use rollapply()

# your data (I called df)
df <- structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L), 
    e = c(1L, 5L), f = c(4, 7)), .Names = c("a", "b", "c", "d", 
"e", "f"), class = "data.frame", row.names = c(NA, -2L))

# transpose and make a zoo object
df2 <- zoo(t(df))

#rollapply to get means and transpose back
means <- t(rollapply(df2, width=2, by=2, FUN=mean))

# adding the combined column names you requested
colnames(means) <- apply(matrix(names(df), nrow=2), 2, paste, collapse=", ") 


HTH


--
View this message in context: 
http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4143329.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

Reply via email to