I have the following example data set:
data.frame(SEX=c("M","F","M","F"),COMPLAINT=c("headache","headache", "dizziness", "dizziness"),
reports=c(5,4,9,12), users = c(1250,3460,2500,1850))
SEX COMPLAINT reports users
1 M headache 5 1250
2 F headache 4 3460
3 M dizziness 9 2500
4 F dizziness 12 1850
My question is how to merge rows 1 and 2 , and 3 and 4 so that my data frame is as follows:
COMPLAINT reports_male reports_female users_male users_female
1 headache 5 4 1250 3460
2 dizziness 9 12 2500 1850
Anyone got a quick solution that I can use for a (much) larger dataset?