accessing current factor in tapply
Here's a way (but as Sundar Dorai-Raj suggests, it might be easier to use a
for loop.)
> cc <- 1:10
> ff <- rep(c("a","b"),5)
> # a different function, so that we can see what data and what label it gets
> data.lab <- function(data,lab) paste(paste(data, collapse=" "),
paste(as.character(lab), collapse=" "), sep="/")
> # ii is indices of each group of ff
> ii <- tapply(cc, ff, c)
> sapply(seq(along=ii), function(j, ii, cc, labs)
data.lab(data=cc[ii[[j]]],lab=labs[j]), ii=ii, cc=cc, labs=names(ii))
[1] "1 3 5 7 9/a" "2 4 6 8 10/b"
>
>
At Thursday 06:13 PM 4/17/2003 +0100, you wrote:
G'Day,
I want to access in a function called from tapply the current factor. In
my example below, all I want to do is to write the current factor on each
histogram. Needless to say my example does not work. I would be grateful
for pointers in the right direction.
Many thanks
Bernie McConnell
Sea Mammal Reserach Unit
cc <- 1:10
ff <- rep(c("a","b"),5)
pp<- function(x,f) {
hist(x, main=as.character(f))
}
tapply(aa, ff, pp, f=ff)
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help