I tried looking for help but I couldn't locate the exact solution. I have data that has several variables. I want to do several sample simulations using only two of the variables (eg: say you have data between people and properties owned. You only want to check how many in the samples will come up with bicycles) to estimate probabilities and that sort of thing. Now, I can only do a simulation in terms of this code: sample(1:10, size 15, replace = TRUE). I do not know how select specific variables only. I'll appreciate the help -- View this message in context: http://r.789695.n4.nabble.com/Simulation-tp3329173p3329173.html Sent from the R help mailing list archive at Nabble.com.
Well, knowing how your data looks like would definitely help! Say your data object is called "mydata", just paste the output from dput(mydata) into the email you want to send to the list. Ivan Le 3/1/2011 04:18, bwaxxlo a ?crit :> I tried looking for help but I couldn't locate the exact solution. > I have data that has several variables. I want to do several sample > simulations using only two of the variables (eg: say you have data between > people and properties owned. You only want to check how many in the samples > will come up with bicycles) to estimate probabilities and that sort of > thing. > Now, I can only do a simulation in terms of this code: sample(1:10, size > 15, replace = TRUE). > I do not know how select specific variables only. > I'll appreciate the help >-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
----------------------------------------> Date: Mon, 28 Feb 2011 19:18:18 -0800 > From: kadodamball at hotmail.com > To: r-help at r-project.org > Subject: [R] Simulation > > I tried looking for help but I couldn't locate the exact solution. > I have data that has several variables. I want to do several sample > simulations using only two of the variables (eg: say you have data between > people and properties owned. You only want to check how many in the samples > will come up with bicycles) to estimate probabilities and that sort of > thing. > Now, I can only do a simulation in terms of this code: sample(1:10, size > 15, replace = TRUE). > I do not know how select specific variables only. > I'll appreciate the helpThis is probably not the best R but you can do something like either of these. Note that this is just the easiest derivative of stuff I already had and can be fixed to your needs, I usually use runif instead of sample for example. The first example probably being much less efficient than the second, df<-data.frame(a=.1*rnorm(100), b=(1:100)/100,c=(1:100)/100+.1*rnorm(100)) res=1:100; for ( i in 1:100) {res[i]=cor(df[which(runif(100)>.9),])[1,3] } res hist(res) res=1:100; for ( i in 1:100) {wh=which(runif(100)>.9); res[i]=cor(df$a[wh],df$c[wh]); } res> > -- > View this message in context: http://r.789695.n4.nabble.com/Simulation-tp3329173p3329173.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.