Lauri Nikkinen wrote:
>
> Suppose I have a following data set.
>
> y1 <- rnorm(20) + 6.8
> y2 <- rnorm(20) + (1:20*1.7 + 1)
> y3 <- rnorm(20) + (1:20*6.7 + 3.7)
> y <- c(y1,y2,y3)
> var1 <- rep(1:5,12)
> z <- rep(1:6,10)
> f <- gl(3,20, labels=paste("lev", 1:3, sep=""))
> d <- data.frame(var1=v
Well, I finally found a roundabout
fun <- function(x, y) sum(x)/max(y)
aggregate(vsid$lev, list(vsid$month, vsid$year), fun, y=by(vsid$date,
vsid$month, function(x) length(unique(x
Thanks,
Lauri
2007/10/2, Lauri Nikkinen <[EMAIL PROTECTED]>:
> Thanks Petr for your kind answer. I got it now b
Thanks Petr for your kind answer. I got it now but it seems that
argument y will not be split by "list(vsid$month, vsid$year)" in the
aggregate function. I should get number of days in each month in the
denominator with "length(unique(y))" but instead I get sum of days in
months in the denominator.
Hi
[EMAIL PROTECTED] napsal dne 02.10.2007 13:19:09:
> Thanks Petr,
>
> Yes, your code seems to work. But when I try to reproduce it with my
> original data set
>
> fun <- function(x, y) sum(x)/length(unique(y))
> aggregate(vsid$lev, list(vsid$month, vsid$yeari), fun,
vsid$lev=vsid$date)
Shal
Thanks Petr,
Yes, your code seems to work. But when I try to reproduce it with my
original data set
fun <- function(x, y) sum(x)/length(unique(y))
aggregate(vsid$lev, list(vsid$month, vsid$yeari), fun, vsid$lev=vsid$date)
I get
Error: syntax error, unexpected EQ_ASSIGN, expecting ',' in
"aggreg
5 matches
Mail list logo