One issue I see in your code is that you userSurv$dxyear to refer to variables. In general with tidyverse function, you never need to do this -- you can just use the bare column names like dxyear. Is this what you're looking for?
library(tidyverse)
df <- tribble(
~CaseID, ~dxyear, ~Gender,
41218, 2012, "Male",
41219, 1997, "Female",
41220, 2008, "Female",
41221, 2008, "Male",
41222, 2008, "Male",
41223, 2010, "Female",
41224, 2005, "Female",
41225, 2000, "Male",
41226, 1993, "Female",
41227, 2001, "Male"
)
df %>%
count(dxyear, Gender) %>%
pivot_wider(names_from = dxyear, values_from = n)
#> # A tibble: 2 x 9
#> Gender `1993` `1997` `2000` `2001` `2005` `2008` `2010` `2012`
#> <chr> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1 Female 1 1 NA NA 1 1 1 NA
#> 2 Male NA NA 1 1 NA 2 NA 1
Created on 2020-06-09 by the reprex package (v0.3.0)