Looking for some assistance as I am at my wit's end. I thought this was going to be so simple!
I have a dataset with which I'd like to do some crosstabulations in dplyr. I want to make a table with Gender for rows, dxyear for columns and the total for each. Based on what I found online, I made the following code:
x <- Surv%>% group_by(Surv$dxyear,Surv$Gender)%>% summarise(n=n())%>% spread(Surv$dxyear,n)
I got the error message:
must evaluate to a single number or a column name, not a double vector
I tried replacing the spread function with pivot_wider:
which resulted in the error message:
Error: Unknown columns 2012
I tried converting
Surv$dxyear to a character variable, but it didn't make a difference. Also, as for the spread function error, I've googled it for two days, but no one seems to explain what it actually means and their solutions don't look much different than my code (or aren't relevant). Any assistance would be greatly appreciated!