I have a data frame in R with two columns with logical conditions that looks like this :
check1 = as.logical(c(rep("TRUE",3),rep("FALSE",2),rep("TRUE",3),rep("FALSE",2)))
check2 = as.logical(c(rep("TRUE",5),rep("FALSE",2),rep("TRUE",3)))
dat = cbind(check1,check2)
resulting to :
check1 check2
[1,] TRUE TRUE
[2,] TRUE TRUE
[3,] TRUE TRUE
[4,] FALSE TRUE
[5,] FALSE TRUE
[6,] TRUE FALSE
[7,] TRUE FALSE
[8,] TRUE TRUE
[9,] FALSE TRUE
[10,] FALSE TRUE
I want to roll calculate the percentage of TRUEs on each column which ideally must look like this :
check1 | check2 |
---|---|
1/1 | 1/1 |
2/2 | 2/2 |
3/3 | 3/3 |
3/4 | 4/4 |
3/5 | 5/5 |
4/6 | 5/6 |
5/7 | 5/7 |
6/8 | 6/8 |
6/9 | 7/9 |
6/10 | 8/10 |
maybe ...
dat%>%
mutate(cumsum(check1)/seq_along(check1))
Any help ?