Based on help files and searching the archives and help from the listserv I
have managed to build my monte carlo program.
However I cannot get the proper syntax for running the loop and storing the
output of each loop (which is a vector) into a matrix.
I took out some of the crazy code I was
I'm not sure I've completely understood this, but would this do what you want:
for (i in 1:N){
aa - sample(a, replace=TRUE)
c -data.frame(b,aa)
output - by(c, aa, function(x) sum(x$b))
output.matrix[,i] - as.vector(output)
}
On 17/06/07, Economics Guy [EMAIL PROTECTED] wrote:
Based on
That gives:
Error in output.matrix[, i] - as.vector(output.vector) :
number of items to replace is not a multiple of replacement length
But I think that is close.
Thanks,
EG
On 6/17/07, David Barron [EMAIL PROTECTED] wrote:
I'm not sure I've completely understood this, but would
I think this does it for you:
a -c(A,C,B,A,B,C)
b -c(10,20,30,40,50,60)
C -data.frame(a,b) # don't use 'c' as it is a primitive function - canbe
confusing
N=10 #Number of Loops
output.matix - replicate(N, function(x){
+ .samp - C[sample(nrow(C), replace=TRUE), ]
+
Thanks so much to both of you. I did not exactly use the code from either of
you but your post help me figure out the things I was doing wrong.
For anyone who stumbles upon this thread later, here is the code I used that
made it work:
Thanks Again.
a -c(A,C,B,A,B,C)
b -c(10,20,30,40,50,60)
d