I have a dataframe with column a:
x = data.frame(
"a" = c(F, F, F, T,
F, T, T, F,
T, T, F)
)
I would like to know for every e.g. 4 rows what the frequency of a being T is and apply this value to a new column b, so that for the first 4 rows the frequency of T is 1/4, for the next 4 rows the frequency of T is 2/4 and for the remaining 3 rows the frequency of T is 2/3:
x$b = c(0.25,0,25,0.25,0.25
0.5,0.5,0.5,0.5,
0.66,0.66,0.66)
I can get the frequency of column a by using tapply, but this gives me a list not vector as a result.
I would appreciate answers without use of external libraries.