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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of zhijie zhang Sent: 27 July 2009 16:04 To: r-h...@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@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. ______________________________________________ R-help@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.