r - include an 'outside' matrix when using an apply function on a 'target' matrix -
friends! i'd take each row of matrix , apply function it. part fine - r code looks this:
apply(rategroup, 1, function(x) do.call(groupcoord(x), as.list(x)))
and each row of 'rategroup' goes function 'groupcoord'
...but if want function 'groupcoord' use matrix outside of function, 1 same each row of 'rategroup')?
...or, bonus question: if wanted matrix outside of function updated 1 progresses through rows of 'rategroup'?
sorry don't have examples here, because cannot work...but do* have code below running first row of 'rategroup' through function, involves 'outside' matrix called 'overlap'
thank insights!
==
candidates <- 19 raters <- 12 groupsize <- 4 overlap<-matrix(0,nrow = raters, ncol = raters) ratenum<-1:raters groupcoord <- function(a,lap) { x1 <- a[1] x2 <- a[2] x3 <- a[3] x4 <- a[4] lap[x2,x1] <- lap[x2,x1] + 1 lap[x3,x1] <- lap[x3,x1] + 1 lap[x4,x1] <- lap[x4,x1] + 1 lap[x3,x2] <- lap[x3,x2] + 1 lap[x4,x2] <- lap[x4,x2] + 1 lap[x4,x3] <- lap[x4,x3] + 1 return(lap) } rategroup<-replicate(candidates, sample(raters, size=groupsize, replace=false)) rategroup<-t(apply(rategroup, 2, sort)) groupcoord(rategroup[1,],overlap)
Comments
Post a Comment