[R] incorrect number of dimensions
Marie-Eve St-Onge
marie-eve.st-onge at outlook.com
Thu Sep 11 17:52:39 CEST 2014
Dear all, I'm trying the following experiment simulation, but I'm receiving this error:
> probs()Error in x[j, 4] : incorrect number of dimensions
however, the simulation works fine outside the function statement{}. What am I doing wrong?
# Create some fake data and call the function: df <- data.frame(y1 = rpois(5, 9),y2 = rpois(5, 7), y3 = rpois(5, 8), n = rpois(5, 100))
probs = function(x='df', j=5, export=1){ p=gtools::rdirichlet(100000, x[j,4] * c(x[j,1],x[j,2],x[j,3], 1-x[j,1]-x[j,2]-x[j,3])/100+1 )if(export==1){ mean(p[,1] > p[,3])} else { return(p)} }
Eve
[[alternative HTML version deleted]]
More information about the R-help
mailing list