I have a dataframe similar to the one below:
study_name = c("ESF", "ESF", "ESF","AAB" )
results= c("alive", "alive", "dead", "dead")
df1 = data_frame(study_name,results, place)
I was trying to use tidyverse
and groupby
the study_name
and then count alive
and dead
but it didn't work. This is what I tried to do:
df1 <- m_df %>%
group_by(study_name) %>%
summarise(n_alive=n_distinct("alive"),
n_dead=n_distinct("dead"))
This is how I wanted the re-arrangement and count to be as in df2
alive= c(2, 0)
study_name = c("ESF","AAB" )
dead= c(1, 1)
df2 =data_frame(study_name, alive, dead)