There is a code from SPSS Syntax do if sub(ATVK,2,2)="01". comp strata=1. else if sub(ATVK,2,2)>="05" and sub(ATVK,2,2)<="27". comp strata=3. else if sub(ATVK,4,2)>"20" or sub(ATVK,6,2)>"20". comp strata=4. else if sub(ATVK,4,2)>"00". comp strata=2. end if. value labels strata 1 "R 2 "Li" 3 "M" 4 "La". How can i rewrite it in R code? -- View this message in context: http://r.789695.n4.nabble.com/From-SPSS-Syntax-to-R-code-tp3302666p3302666.html Sent from the R help mailing list archive at Nabble.com.
An embedded and charset-unspecified text was scrubbed... Name: nem el?rhet? URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110212/381cdc55/attachment.pl>
You might want to take a look at Bob Muenchen's book "R for SAS and SPSS Users" .... There is an 80 page preview at ...... http://rforsasandspssusers.com/ Additionally, there is lots of documentation for getting started with R on the CRAN website ....http://cran.r-project.org/ HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/From-SPSS-Syntax-to-R-code-tp3302666p3302707.html Sent from the R help mailing list archive at Nabble.com.
On 11-02-12 05:08, beky wrote:> There is a code from SPSS Syntax > > do if sub(ATVK,2,2)="01". > comp strata=1. > else if sub(ATVK,2,2)>="05" and sub(ATVK,2,2)<="27". > comp strata=3. > else if sub(ATVK,4,2)>"20" or sub(ATVK,6,2)>"20". > comp strata=4.Note that your first statement is overwritten by the one below.> else if sub(ATVK,4,2)>"00". > comp strata=2. > end if. > > value labels strata 1 "R 2 "Li" 3 "M" 4 "La". > > How can i rewrite it in R code?# guessing your data ATVK <- paste( sample(LETTERS, 100, repl=T), sample(sprintf("%02d", 0:30), 100, repl=T), sample(sprintf("%02d", 0:30), 100, repl=T), sample(sprintf("%02d", 0:30), 100, repl=T), sample(letters, 100, repl=T), sep="" ) strata <- factor(rep(NA, 100), levels=c("R", "Li", "M", "La")) # making the "as.nimeric(stubstr(...))" convenient atsub2 <- as.numeric(substr(ATVK, 2, 3)) atsub4 <- as.numeric(substr(ATVK, 4, 5)) atsub6 <- as.numeric(substr(ATVK, 6, 7)) # didn't find a one-liner, however, this should work strata[atsub2==1] <- "R" strata[atsub2>=5 | atsub2<=27] <- "M" # change statements to prevent overwriting strata[atsub4>0] <- "Li" strata[atsub4>20 | atsub6>20] <- "La" summary(strata) HTH, *S* -- Sascha Vieweg, saschaview at gmail.com
On Saturday, February 12, 2011 05:08:06 am beky wrote:> There is a code from SPSS Syntax > > do if sub(ATVK,2,2)="01". > comp strata=1. > else if sub(ATVK,2,2)>="05" and sub(ATVK,2,2)<="27". > comp strata=3. > else if sub(ATVK,4,2)>"20" or sub(ATVK,6,2)>"20". > comp strata=4. > else if sub(ATVK,4,2)>"00". > comp strata=2. > end if. > > value labels strata 1 "R 2 "Li" 3 "M" 4 "La". > > How can i rewrite it in R code?It would be helpful if an example of data were included in your request. BTW, I believe there's a missing '"' in the last line of code. Shouldn't "R be "R"? JWDougherty