[R-sig-eco] plyr and mvabund, conceptual issue
Hadley Wickham
h.wickham at gmail.com
Wed Oct 29 14:38:46 CET 2014
On Wed, Oct 29, 2014 at 4:23 AM, Eduard Szöcs <eduardszoecs at gmail.com> wrote:
> Hai Kendra,
>
> i've used a simple for-loop to do this in the past.
>
> Something along these lines:
>
>
> ###-----------------------------------------------------------------
> mymv <- function(response, env, zone) {
> df <- data.frame(env = env, zone = zone)
> out <- NULL
> for (i in levels(zone)) {
> rsp <- mvabund(response[zone == i, ])
> out[[i]]$mod <- manyglm(rsp ~ env, data = df[zone == i, ])
> out[[i]]$anova <- anova(out[[i]]$mod, p.uni = "adjusted", resamp =
> "perm.resid", nBoot = 10)
> }
> return(out)
> }
If you're going to use a for-loop, you need to preallocate the output:
out <- vector("list", length(levels(zone))
Otherwise each iteration of the loop needs to copy all previous output
to a new location, making things rather slow.
Hadley
--
http://had.co.nz/
More information about the R-sig-ecology
mailing list