I have a dateset, df:
state id year yes
ga 1 2020 10%
ca 2 2020 10%
va 1 2020 20%
ga 1 2001 10%
ca 2 2001 20%
va 1 2001 10%
I wish for the ouput to look like this:
state id year yes
ga 1 2001 10%
ga 1 2020 10%
ca 2 2001 20%
ca 2 2020 10%
va 1 2001 10%
va 1 2020 20%
dput:
structure(list(state = structure(c(2L, 1L, 3L, 2L, 1L, 3L), .Label = c("ca",
"ga", "va"), class = "factor"), id = c(1L, 2L, 1L, 1L, 2L, 1L
), year = c(2020L, 2020L, 2020L, 2001L, 2001L, 2001L), yes = structure(c(1L,
1L, 2L, 1L, 2L, 1L), .Label = c("10%", "20%"), class = "factor")), class = "data.frame", row.names =
c(NA,
-6L))
This is what I have tried
library(dplyr)
df1<-df %>% group_by(state)