When trying to create dummy variables there is an issue where a row is being merged for some reason. This results in a row being associated with two groups, hence not a dummy variable. The following code reproduces the issue.
df = data.frame(group = c(4, 2, 3, 3, 4, 4), time = c(0.1, 0.2, 0.3, 0.3, 0.3, 0.4), age = c(65, 86, 49, 71, 71, 76), year = c(72, 74, 72, 76, 76, 77), death = c(1, 1, 1, 1, 1, 1))
df %>% mutate(i=1) %>% spread(group, i, fill=0)
You can see after running the code that there is a row that is merged resulting in a subject that is in two groups at once. Is this an error with the code or an error with the function?