Thanks, Rui.
It works great.
Atem.
On Saturday, April 5, 2014 4:46 AM, Rui Barradas <ruipbarradas@sapo.pt> wrote:
 
Hello,

Maybe the following will do.

dat <- structure(...)

aggregate(dat[5:8], dat[c(1, 2, 4)], FUN = mean)


Hope this helps,

Rui Barradas


Em 05-04-2014 06:37, Zilefac Elvis escreveu:
> Hi,
>
> I have daily data arranged by date and site. Keeping the number of columns as there are, I will like to aggregate (FUN=mean) from daily to monthly the following data (only part is shown here) which starts in 1971 and ends in 1980.
>
>
> structure(list(Year = c(1971, 1971, 1971, 1971, 1971, 1971, 1971,
> 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971,
> 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971,
> 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971,
> 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971,
> 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971,
> 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971,
> 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971,
> 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971,
> 1971, 1971, 1971, 1971, 1971), Month = c(1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1), Day = c(1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1), Site = c("GGG1", "GGG2", "GGG3", "GGG4",
> "GGG5", "GGG6", "GGG7", "GGG8", "GGG9", "GG10", "GG11", "GG12",
> "GG13", "GG14", "GG15", "GG16", "GG17", "GG18", "GG19", "GG20",
> "GG21", "GG22", "GG23", "GG24", "GG25", "GG26", "GG27", "GG28",
> "GG29", "GG30", "GG31", "GG32", "GG33", "GG34", "GG35", "GG36",
> "GG37", "GG38", "GG39", "GG40", "GG41", "GG42", "GG43", "GG44",
> "GG45", "GG46", "GG47", "GG48", "GG49", "GG50", "GG51", "GG52",
> "GG53", "GG54", "GG55", "GG56", "GG57", "GG58", "GG59", "GG60",
> "GG61", "GG62", "GG63", "GG64", "GG65", "GG66", "GG67", "GG68",
> "GG69", "GG70", "GG71", "GG72", "GG73", "GG74", "GG75", "GG76",
> "GG77", "GG78", "GG79", "GG80", "GG81", "GG82", "GG83", "GG84",
> "GG85", "GG86", "GG87", "GG88", "GG89", "GG90", "GG91", "GG92",
> "GG93", "GG94", "GG95", "GG96", "GG97", "GG98", "GG99", "G100"
> ), Sim001 = c(8.58, 11.82, 7.72, 8.93, 9.82, 13.93, 10.94, 5.07,
> 11.13, 7.66, 1.06, 14.93, 7.56, 6.18, 10.96, 4.94, 0.79, 4.91,
> 0.68, 4.5, 3.13, 2.91, -2.27, 8.18, 3.87, 5.1, 7.23, 8.55, 1.39,
> 6.85, 4.25, -0.24, 9.86, 9.92, 5.11, 6.14, 8.14, 7.52, 4.19,
> 1.02, -2.43, 6.85, 4.94, 8.11, 7.34, 10.56, -6.52, 2.66, -4.89,
> 0.11, 3.9, 3.87, 2.55, -0.2, 5.09, -2.4, 1.32, 3.49, 4.93, -9.58,
> 9.08, 2.85, 7.71, 4.5, 0.99, 8.72, 12.45, 8.83, 8.94, 5.05, 9.82,
> 11.72, 1.21, 7.92, 3.45, 1.34, 8.25, 2.92, 2.1, -3.19, 4.75,
> -0.3, 1.69, 3.31, 5.18, 2.43, 3.02, -5.31, -6.7, -5.9, -4.73,
> -8.13, -7.67, 3.73, -2.4, 1.46, -4.71, 0.33, -3.11, 2.45), Sim002 = c(-12.67,
> -9.94, -11.94, -10.81, -6.78, -3.39, -7.58, -16.09, -9.96, -8.68,
> 6.14, -12.43, -10.81, -7.58, -0.62, 1.52, 0.83, -3.29, -0.5,
> 1.14, 3.35, 1.1, -5.25, 2, -4.09, 2.28, 2.46, 5.64, 4.64, -12.11,
> -2.21, -16.54, -7.38, -16.33, -7.63, -11.61, -12.78, -12.86,
> -9.99, 4.84, -13.75, -12.33, -13.43, -21.13, -12.63, -3.16, 1.61,
> -2.36, 5.54, 3.59, 1.23, -0.25, -1.49, -1.65, 0.9, -2.29, -2.35,
> -2.01, -2.07, 1.37, -0.64, 4.75, 3.02, 5.44, 3.76, 5.16, 2.54,
> 4.11, 5.03, -1.12, 4.53, -0.15, -4.98, 0.85, -3.04, -0.06, -3.01,
> -1.1, 4.02, 1.77, -3.36, 1.56, -1.63, 1.12, -2.39, -2.05, 4.51,
> 1.52, -0.61, 2.54, 2.88, 6.79, 5.5, -2.36, 4.18, -0.13, 5.68,
> 1.82, 3.21, 0.21), Sim003 = c(4.45, -3.37, -1.17, 4.66, -4.19,
> -3.84, 1.74, 1.26, -7.06, -2.65, -4.88, -4.06, -2.32, -1.64,
> 0.56, 0.31, -0.35, -5.69, 3.35, 4.84, 3.62, 0.77, -3.05, -0.42,
> -2.55, 1.34, 2.89, 3.09, 9.79, 4.98, 9.59, 4.99, 11.77, 13.07,
> 0.41, 10.38, 11.01, 3.43, 6.08, 0.55, 6.49, 2.85, 11.17, 11.32,
> -0.89, -0.48, 10.8, 1.86, 6.63, 5.14, 4.13, 8.72, 15.01, 4.78,
> 5.56, 5.69, 10.39, 8.99, 6.95, 10.59, 3.92, 3.4, 3.95, 0.87,
> 2.28, 1.11, 4.36, 6.21, 1.73, 2.5, 4.19, 1.85, 8.65, 6.24, 7.82,
> 7.43, 5.19, -1.71, -3.16, -2.66, -7, -2.08, 0.36, 8.61, 3.22,
> 7.99, -1.19, 11.38, 10.2, 8.87, 7.23, 8.07, 2.77, 9.61, -1.1,
> -2.05, 6.39, 6.6, -2.89, -6.41), Sim004 = c(-1.31, 4.94, 4.7,
> 2.88, -0.01, 1.83, -7.51, 1.12, 5.25, 5.25, 3.78, 4.94, 2.32,
> 9.83, -1.59, 6.45, 4.26, 3.1, 5.5, 6.94, 2.76, 5.1, 1.95, 15.13,
> -9.18, 2.88, 4.28, -5.01, -0.27, 1.91, -1.46, -0.6, -8.99, -8.79,
> -3.09, -7.09, -5.2, -7.55, -4.04, -3.8, -10.66, -6.34, -3.62,
> -8.49, -2.29, 0.38, 5.25, 8.6, 5.83, 8.94, 9.86, 4.62, 4.33,
> 10.15, 7.87, 9.07, 0.04, 2.85, 6, 4.54, 13.5, 12.39, 11.79, 6.29,
> 15.45, 15.82, 19.79, 13.12, 6.5, -4.63, 1.79, -0.8, 1.29, 8.88,
> 1.28, 6.55, 5.78, 5.46, 2.83, 8, 6.25, 4.94, 5.01, 5.32, 2.95,
> 7.46, 5.71, -3.51, 3.51, 9.46, 8.55, 6.71, 7.36, 10.96, 3.47,
> -1.99, 5.75, 1.56, -4.38, 0.67)), .Names = c("Year", "Month",
> "Day", "Site", "Sim001", "Sim002", "Sim003", "Sim004"), row.names = c(NA,
> 100L), class = "data.frame")
>
> Thanks for your useful solution.
> Atem.
>     [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> 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.

>
	[[alternative HTML version deleted]]


