Dear R users, I have a SAS codes with several loops in it, and i hope to use R to do the same task. The SAS codes are as follows, /*to generate the dataset*/ DATA Single_Simulation; DO se=0 to 1 by 0.01; DO sp=0 to 1 by 0.01; DO DR=0 to 1 by 0.01; TR=(DR+sp-1)/(se+sp-1+1.0e-12); Adjust_Factor=TR/(DR+1.0e-12); OUTPUT; END; END; END; RUN; /*to select some data*/ DATA sampledata; SET Single_Simulation; IF DR=0.02 & sp=1; RUN; #I tried the following codes with R,failed num<-seq(0, 1, by = 0.01) for (se in num) { for (sp in num) { for (DR in num) { TR=(DR+sp-1)/(se+sp-1+1.0e-12) Adjust_Factor=TR/(DR+1.0e-12) } } } My questions are, 1. What is the correct codes for R to do the similar task? 2. Sometimes, the simulated dataset are very large, so i need to put the generated dataset in a file with large disk place, not in the memory, how to do it? SAS can do it with the 'libname' argument, do R have the similar method? Thanks a lot. [[alternative HTML version deleted]]
singleSim <- expand.grid(se = 0:100/100, sp = 0:100/100, DR = 0:100/100) singleSim <- within(singleSim, { TR <- (DR+sp-1)/(se+sp-1+1.0e-12) AdjustFactor <- TR/(DR+1.0e-12) }) sampleData <- subset(singleSim, DR == .02 & sp == 1) write.csv(sampleData, "output.csv") Hope this helps Matt mangosolutions - R and S consultants Tel +44 (0)1249 767700 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of zhijie zhang Sent: 27 July 2009 16:04 To: r-help at stat.math.ethz.ch Subject: [R] How should i change the SAS Codes into R Codes? Dear R users, I have a SAS codes with several loops in it, and i hope to use R to do the same task. The SAS codes are as follows, /*to generate the dataset*/ DATA Single_Simulation; DO se=0 to 1 by 0.01; DO sp=0 to 1 by 0.01; DO DR=0 to 1 by 0.01; TR=(DR+sp-1)/(se+sp-1+1.0e-12); Adjust_Factor=TR/(DR+1.0e-12); OUTPUT; END; END; END; RUN; /*to select some data*/ DATA sampledata; SET Single_Simulation; IF DR=0.02 & sp=1; RUN; #I tried the following codes with R,failed num<-seq(0, 1, by = 0.01) for (se in num) { for (sp in num) { for (DR in num) { TR=(DR+sp-1)/(se+sp-1+1.0e-12) Adjust_Factor=TR/(DR+1.0e-12) } } } My questions are, 1. What is the correct codes for R to do the similar task? 2. Sometimes, the simulated dataset are very large, so i need to put the generated dataset in a file with large disk place, not in the memory, how to do it? SAS can do it with the 'libname' argument, do R have the similar method? Thanks a lot. [[alternative HTML version deleted]] ______________________________________________ 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.
I see Matt Aldridge has given you the answers to your specific questions. If you are used to using SAS you might find Bob Meunchen's book "Muenchen, R. A. (2008). R for SAS and SPSS Users (1st ed.). Springer." useful. A shorter version is available as a pdf at http://rforsasandspssusers.com/. The pdf is a very useful guide for anyone beginning to use R. --- On Mon, 7/27/09, zhijie zhang <rusers.sh at gmail.com> wrote:> From: zhijie zhang <rusers.sh at gmail.com> > Subject: [R] How should i change the SAS Codes into R Codes? > To: r-help at stat.math.ethz.ch > Received: Monday, July 27, 2009, 11:03 AM > Dear R users, > ? I have a SAS codes with several loops in it, and i > hope to use R to do the > same task. The SAS codes are as follows, > /*to generate the dataset*/ > DATA Single_Simulation; > DO se=0 to 1 by 0.01; > ? DO sp=0 to 1 by 0.01; > ???DO DR=0 to 1 by 0.01; > ? ? TR=(DR+sp-1)/(se+sp-1+1.0e-12); > ? ? Adjust_Factor=TR/(DR+1.0e-12); > ? ? OUTPUT; > ???END; > ? END; > END; > RUN; > > /*to select some data*/ > DATA sampledata; > SET Single_Simulation; > IF DR=0.02 & sp=1; > RUN; > > #I tried the following codes with R,failed > num<-seq(0, 1, by = 0.01) > for (se in num) { > for (sp in num) { > ???for (DR in num) { > ? ? TR=(DR+sp-1)/(se+sp-1+1.0e-12) > ? ? Adjust_Factor=TR/(DR+1.0e-12) > ? } > } > } > > My questions are, > 1. What is the correct codes for R to do the similar task? > 2. Sometimes, the simulated dataset are very large, so i > need to put the > generated dataset in a file with large disk place, not in > the memory, how to > do it? SAS can do it with the 'libname' argument,? do > R have the similar > method? > ? Thanks a lot. > > ??? [[alternative HTML version deleted]] > > ______________________________________________ > 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. >__________________________________________________________________ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now http://ca.toolbar.yahoo.com.