[R] Seeking help with a loop

Greg Blevins
Wed, 03 Aug 2005 14:09:31 -0000

Hello R Helpers,

After spending considerable time attempting to write a loop (and searching the
help archives) I have decided to post my problem.

In a dataframe I have columns labeled:

q33a q33b q33c...q33r    q35a q35b q35c...q35r

What I want to do is create new variables based on the following logic:
newfielda <- ifelse(q35a==1, q33a, NA)
newfieldb <- ifelse(q35b==1, q33b, NA)
...
newfieldr

What I did was create two new dataframes, one containing q33a-r the other q35a-r
and tried to loop over both, but I could not get any of the loop syntax I tried
to give me the result I was seeking.

Any help would be much appreciated.

Greg Blevins
Partner
The Market Solutions Group, Inc.
Minneapolis, MN

Windows XP, R 2.1.1