I have a dataframe that looks like this:
example <- data.frame(
sub = c(rep(1091, 3),
rep(2091,4)),
completed_sessions = c(1,0,1,0,1,1,1)
)
I want to get the percent_complete
by sub
, with it calculated by num_complete/total_entries. num_complete
is the count of '1's per sub
, total_entries
is the total number of observations of PID
. How can I do this?
This is the desired output:
example_solution <- data.frame(
sub = c(1091, 2091),
num_complete = c(2,3),
total_entries = c(3,4),
percent_complete = c(66.67, 75.00)
)
Thank you!