y***6 发帖数: 46 | 1 If I have the following 3 by 3 matrix
A=[100 1 .3 <-first row
100 1 .6 <-second row
100 1 .9]<-third row
And I want to use each row of A to generate Bernoulli random variables
(With values in column 1, 100 in this example, being the number of random
numbers generated, second column being the size, and third column being the
trial probability). How to perform this task without using loops?
To be more specific, the resulting matrix B(3 by 100 matrix) shou | C******t 发帖数: 72 | 2 t(apply(a,1,function(x) rbinom(x[1],x[2],x[3]))) | D******n 发帖数: 2836 | 3 there u go
result<-t(mapply(rbinom,A[,1],A[,2],A[,3]))
variables
the
be
【在 y***6 的大作中提到】 : If I have the following 3 by 3 matrix : A=[100 1 .3 <-first row : 100 1 .6 <-second row : 100 1 .9]<-third row : And I want to use each row of A to generate Bernoulli random variables : (With values in column 1, 100 in this example, being the number of random : numbers generated, second column being the size, and third column being the : trial probability). How to perform this task without using loops? : To be more specific, the resulting matrix B(3 by 100 matrix) shou
| y***6 发帖数: 46 | |
|