[R] use of 'apply' for 'hist'

Dieter Menne dieter.menne at menne-biomed.de
Sat Dec 18 18:26:12 CET 2010



casperyc wrote:
> 
> Hi all,
> 
> ##########################################
> dof=c(1,2,4,8,16,32)
> Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof))
> par(mfrow=c(2,6))
> apply(Q5,2,hist)
> myf=function(x){ qqnorm(x);qqline(x) }
> apply(Q5,2,myf)
> ##########################################
> 
> Apart from using a loop, is there are fast way to 'add' the titles to be
> more informative?
> 
> 

If you type "apply" (no ()) you will find that it is not much more than an
decorated generic loop. I believe that this is case where using a loop.
Otherwise, you could convert you matrix to a data frame, add the degrees of
freedom.... too much work for a loop where plotting anyway has the largest
overhead.

Others may disagree, but I believe the apply-wars have ended at the time
when browser wars ended.

Dieter

-- 
View this message in context: http://r.789695.n4.nabble.com/use-of-apply-for-hist-tp3093811p3093847.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list