Description Usage Arguments Author(s) See Also Examples
Apply a function on a variable over levels of an grouping factor. A wrapper for split()
and is similar in functionality to by()
but with more options for output.
1 |
x |
a string or numeric vector. |
id |
grouping factor with |
FUN |
Function to apply over |
regroup |
logical, if TRUE returns result in the same structure as |
... |
Additional arguments passed to FUN |
Christopher Steven Marcum
1 2 3 4 5 6 7 8 | data(Indometh)
glapply(Indometh$conc,Indometh$Subject,FUN=mean)
x<-rep(sample(1:10),2)
id<-rep(letters[1:5],4)
glapply(x,id,FUN=function(x)sum((x-mean(x))^2),regroup=FALSE)
glapply(x,id,FUN=function(x)sum((x-mean(x))^2),regroup=TRUE)
#Compare with output produced by by()
by(x,id,function(x)sum((x-mean(x))^2))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.