I'm learning R and am converting some code from SPSS into R.  My background
is in SAS/SPSS so the vectorization is new to me and I'm trying to learn
how to NOT use loops...or use them sparingly.  I'm wondering what the
most efficient to tackle a problem I'm working on is. Below is an example
piece of code.  Essentially what it does is set a variable to zero, loop
through item responses, and add one if a condition is met. For example, if
item one was responded as a 1 then add one to the final variable.  If item
two was responded as a 2 then add one to the final variable.  I have to do
this for five scales with each scale having 6 items half of which may have
the 1 response pattern and half the 2 pattern.

Any suggestions on how best to tackle this in R would be helpful.

Craig

**********
Old SPSS code sample
**********

Compute Variable = 0.

IF (item1 = 1) Variable = Variable +1 .

IF (item2= 2) Variable = Variable +1 .

IF (item3 = 1) Variable = Variable +1.

IF (item4 = 2) Variable = Variable +1.

EXECUTE .

        [[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.

Reply via email to