[R] averaging within columns
Rau, Roland
Rau at demogr.mpg.de
Mon Feb 28 10:51:49 CET 2005
Hi,
> I'm hoping there is something like
>
> mean(dataname$wtime[name])
>
> which will just create a column with length equal to the number of
> different names (levels) and an average wtime for each. So
> far though,
> I haven't had much luck figuring that one out.
>
Does the following code do what you want?
#### given you have the data like this:
name <- c(rep("jo", 4), rep("tim",3), rep("ro", 2))
wtime <- c(1,2,1,3,3,2,2,1,2)
mydf <- data.frame(name=name, wtime=wtime)
#### this should give you the desired result
tapply(X=mydf$wtime, INDEX=list(mydf$name), FUN=mean)
Hope this turns out to be useful.
Best,
Roland
+++++
This mail has been sent through the MPI for Demographic Rese...{{dropped}}
More information about the R-help
mailing list