[R] Matrix oriented computing

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Aug 26 15:25:59 CEST 2005


Marc Schwartz <MSchwartz at mn.rr.com> writes:

> x <- c(0.005, 0.010, 0.025, 0.05, 0.1, 0.5, 0.9, 
>        0.95, 0.975, 0.99, 0.995)
> 
> df <- c(1:100)
> 
> mat <- sapply(x, qchisq, df)
>
> > dim(mat)
> [1] 100  11
>  
> > str(mat)
>  num [1:100, 1:11] 3.93e-05 1.00e-02 7.17e-02 2.07e-01 4.12e-01 ...

outer() is perhaps a more natural first try... It does give the
transpose of the sapply approach, though. 

round(t(outer(x,df,qchisq)),2)

should be close. You should likely add dimnames.


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list