Dominic, It's great that you provided some example data, but a much smaller data frame would have sufficed. For example, 10 randomly selected rows from your data ...
LF <- structure(list(Serra.da.Foladoira = c(27.335652173913, 25.4632608695652, 24.464652173913, 22.550652173913, 22.2177826086956, 29.3744782608695, 24.1317826086956, 25.5464782608695, 27.7517391304348, 25.172), Santiago = c(32.6199565217391, 27.9597826086956, 32.7863913043478, 25.2136086956521, 23.7573043478261, 32.6199565217391, 28.6671304347826, 27.9597826086956, 29.7489565217391, 23.5492608695652), Sergude = c(31.7877826086956, 27.4604782608695, 26.1706086956521, 25.8377391304348, 26.5034782608695, 33.2856956521739, 30.4979130434782, 30.7059565217391, 30.8307826086956, 31.9542173913043), Rio.Do.Sol = c(30.3730869565217, 25.7545217391304, 25.421652173913, 24.1317826086956, 23.4660434782608, 31.1220434782608, 25.8377391304348, 25.8793478260869, 30.7059565217391, 24.464652173913 ), V5 = c(10L, 2L, 2L, 11L, 3L, 8L, 8L, 3L, 8L, 6L)), .Names = c("Serra.da.Foladoira", "Santiago", "Sergude", "Rio.Do.Sol", "V5"), row.names = c(1017L, 778L, 400L, 1403L, 86L, 1311L, 598L, 1536L, 605L, 520L), class = "data.frame") Try this code to calculate the mean of each of the first four columns for each value of the fifth column ... aggregate(LF[, 1:4], list(month=LF$V5), mean) The sapply() approach doesn't have a built in "by" type of argument. Jean Dominic Roye <dominic.r...@gmail.com> wrote on 08/06/2012 09:34:58 AM: > > Hello everyone, > > > I have a dataset with 5 colums (4 colums with thresholds of weather > stations and one with month - data of 5 years). Now I would like to > calculate the average for each month. > > I tried this unsuccessfully: > > lf.med <- sapply(LF[,1:4],mean,LF[,5]) > > Error in mean.default(X[[1L]], ...) : > 'trim' must be numeric and have length 1 > > > With > > lf.med <- by(LF[,1:4],LF[,5],mean) > > It works, but its deprecated. > > > > Any help is greatly appreciated!!! Thanky everybody`!! > > Dominic > > > dput(LC) > structure(list(Serra.da.Foladoira = c(21.1359565217391, 21.7184782608695, > 23.5492608695652, 23.4660434782608, 23.6740869565217, 21.1775652173913, < SNIPPED > > 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, > 12L, 12L)), row.names = c(NA, -1826L), .Names = c("Serra.da.Foladoira", > "Santiago", "Sergude", "Rio.Do.Sol", "V5"), class = "data.frame") [[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.