Open willpearse opened 7 years ago
matrix[rows, col]
...can be used to subset
Hey Dr. Pearse,
I know this isn't what you suggested, since I didn't quite understand the matrix approach, but is it suitable?
Still not entirely comfortable with its assumption that if a species is not present at one site, then it's absent at all the others. Any recommendations for that?
Your approach is fine. I am surprised you know how to use do.call
, but I suppose this is what comes from using plyr
et al.!
As far as your assumption, I wouldn't be either - you've made a slight slip. It's not whether a species is present at a single site that determines all sites. The sequence is:
rbinom
)rpois
)...thus you go through the whole 'hurdle' process for each site. Does that make sense? I'm also online now on appear.in if you want to talk with me.
Yeah I think so. Would a repeat loop work if I implemented it into the original function?
Nevermind, fixed it. Is this is alright?
hurdle2 <- function(sitenum, spnum){
r <- matrix(nrow=sitenum, ncol=spnum)
for(i in 1:spnum){
r[,i] <- hurdle1(sitenum)
}
return(r)
}
hurdle2(10, 7)
...right? Looks to be! Welcome to the matrix
club. Now, isn't that easier than dplyr
?... :p