Hi Everyone,
I am just starting to get beyond the basics in R and have come to a point where I need some help. I want to restructure some data. Here is what a sample dataframe may look like:
ID  Sex Res Contact
1   M   MA  ABR
1   M   MA  CON
1   M   MA  WWF
2   F   FL  WIT
2   F   FL  CON
3   X   GA  XYZ
I want the data to look like:
ID  SEX Res ABR CON WWF WIT XYZ
1   M   MA  1   1   1   0   0
2   F   FL  0   1   0   1   0
3   X   GA  0   0   0   0   1
What are my options? How would I do this in R? R is so powerful, I figure this is probably a breeze!
In short, I am looking to keep the values of the CONT column and use them as column names in the restructred data frame. I want to hold a variable set of columns constant (in th example above, I held ID, Sex, and Res constant). Also, is it possible to control the values in the restructured data? I may want to keep the data as binary, and sometimes, I may want to have the value be the count of times each contact value exists for each ID.
Any help will be very much appreciated,
Brock