df <- data.frame(dive=factor(sample(c("dive1","dive2", "dive3"),20,replace=TRUE)),speed=runif(20))
> df
dive speed Drift
1 dive1 0.80668490 TRUE
2 dive1 0.53349584 FALSE
3 dive2 0.07571784 TRUE
4 dive2 0.39518628 TRUE
5 dive1 0.84557955 TRUE
6 dive1 0.69121443 FALSE
7 dive1 0.38124950 TRUE
8 dive2 0.22536126 FALSE
9 dive1 0.04704750 FALSE
10 dive2 0.93561651 TRUE
Suppose I have a data frame of this form with a third column named “Drift” where the row values are either “TRUE” or “FALSE”. How would I go about working out the percentage of rows equal to TRUE when “dive” equals a specific value. I.e. when dive==1 what percentage of the “drift” column is “TRUE”?
Thankyou.
You could try: