1

I have a Dataframe with the columns state and runtime

id state        runtime
1  successful   25
2  successful   30
3  failed       30
4  failed       35

I want to calculate a success rate for every runtime in a new dataframe to plot the data later.
Success rate is successful projects divided by all projects

runtime  success_rate
25       1
30       0.5
35       1
Mako
  • 33
  • 4

1 Answers1

0

tidy solution:

library(dplyr)
df %>%
  group_by(runtime) %>%
  summarise(
    success_rate = sum[state=="successful"]/n()
  )
Eric
  • 1,381
  • 9
  • 24