data:
test = data.frame(case=c("cyl","eng","mon"),
worst=c(1,0,1),money=c(123,42,13),girl=c("no","yes","no"))
desired_test= data.frame(case=c("cyl","eng","mon"), worst=c(1,0,1),money=c(123,42,13),girl=c("no","yes","no"),
worst_cyl=c(1,0,0),worst_eng=c(0,0,0),worst_mon=c(0,0,1))
Attempt:
test %>% group_by(case) %>% spread(case,worst,fill=0,sep="_")
Why is not my attempt working?
desired_test
does not seem to make a lot of sense. What are you trying to achieve? In your desired result, is row 2 really about caseeng
? What is the meaning of "worst_cyl" being 0 on row 2? – asachet