Hello R folks.
1) The question that generated the data, which I call Qx:
Which of the following 5 items have you performed in the past month? (multipe
response)
2) How the data is coded in my current dataframe:
The first item that a person selected is coded under a field called Qxfirst; the
second selected under Qxsecond, etc. For the first Person, the NAs mean that that
person only selected two of the five items.
Hypothetical data is shown
Qxfirst Qxsecond Qxthird Qxfourth Qxfifth
Person1 4 2 NA NA NA
Person2 1 3 4 5 NA
Person3 3 2 NA NA NA
3) How I want the data to be be coded:
I want each field to be one of the five items and I want each field to contain a 1 or
0 code--1 if they mentioned the item, 0 otherwise.
Given the above data, the new fields would look as follows:
Item1 Item2 Item3 Item4 Item5
Person1 0 1 0 1 0
Person2 1 0 1 1 1
Person3 0 1 1 0 0
I know how to do this using brute force (by writing bunch of ifelse statements), but
given I have quite a lot of data in the above format, I was hoping a function would
streamline this--I have tried to create a function for this, but my efforts to date
have turned up junk.
Thanks
Greg Blevins
The Market Solutions Group
[[alternative HTML version deleted]]
______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html