-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of Rui Barradas
Sent: Monday, December 17, 2012 12:06 PM
To: eliza botto
Cc: r-help at r-project.org
Subject: Re: [R] mean of each month in data
Hello,
Something like this?
dat <-
structure(list(st = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), .Label = c("Sa", "Ta"), class = "factor"), year = c(1966L,
1966L, 1966L, 1966L, 1966L, 1966L, 1966L, 1966L, 1966L, 1967L,
1967L, 1967L, 1967L, 1967L, 1967L, 1967L, 1967L, 1967L, 1968L,
1968L, 1968L, 1968L, 1968L, 1968L, 1968L, 1968L, 1968L, 1969L,
1969L, 1969L, 1969L, 1969L, 1969L, 1969L, 1969L, 1969L, 1955L,
1955L, 1955L, 1955L, 1955L, 1955L, 1955L, 1955L, 1955L, 1956L,
1956L, 1956L, 1956L, 1956L, 1956L, 1956L, 1956L, 1956L, 1957L,
1957L, 1957L, 1957L, 1957L, 1957L, 1957L, 1957L, 1957L, 1957L,
1958L, 1958L, 1958L, 1958L, 1958L, 1958L, 1958L, 1958L), month = c(1L,
1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L,
3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L,
3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L,
5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L,
10L, 10L, 11L, 11L, 11L, 12L, 12L, 12L), day = c(1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L), population = c(2.4, 2.4, 2.4, 2.4, 2.4,
2.4, 2.3, 2.2, 2.3, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4,
2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.3, 2.2, 2.3, 2.4, 2.4, 2.4, 2.4,
2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.3, 2.2,
2.3, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4,
2.4, 2.4, 2.4, 2.3, 2.2, 2.3, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4,
2.4, 2.4)), .Names = c("st", "year", "month", "day", "population"
), class = "data.frame", row.names = c(NA, -72L))
agg <- aggregate(population ~ st + year + month, data = dat, FUN =
mean)
reshape(agg, direction = "wide",
idvar = c("st", "month"),
timevar = "year",
v.names = "population")
Hope this helps,
Rui Barradas
Em 17-12-2012 17:11, eliza botto escreveu: