You can do something like this
library(tidyr)
library(dplyr)
# Sample data on a copy/paste friendly format
sample_df <- data.frame(
stringsAsFactors = FALSE,
id = c(3475, 3478, 3476, 3479, 3477, 3480),
prof = c("PROF1", "PROF2", "PROF1", "PROF2", "PROF1", "PROF3"),
year = c(1988, 1996, 1998, 2000, 2002, 2004),
degree = c("Undergraduate",
"Undergraduate","Master","Master","Doctoral","Doctoral")
)
sample_df %>%
count(year, degree) %>%
pivot_wider(names_from = degree, values_from = n, values_fill = 0)
#> # A tibble: 6 x 4
#> year Undergraduate Master Doctoral
#> <dbl> <int> <int> <int>
#> 1 1988 1 0 0
#> 2 1996 1 0 0
#> 3 1998 0 1 0
#> 4 2000 0 1 0
#> 5 2002 0 0 1
#> 6 2004 0 0 1
Created on 2020-10-03 by the reprex package (v0.3.0)
If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.