I have this framework:
x <- data.frame(
name = rep(letters[1:4], each = 2),
condition = rep(c("A", "B"), times = 4),
value = c(2,10,4,20,8,40,20,100)
)
I want to group by name and divide the value of the lines with condition == "B"by those that are with condition == "A"to get the following:
data.frame(
name = letters[1:4],
value = c(5,5,5,5)
)
I know something like this can get me pretty close:
x$value[which(x$condition == "B")]/x$value[which(x$condition == "A")]
but I was wondering if there is an easy way to do this with dplyr (My dataframe is an example of a toy, and I got to it, catching a few calls group_byand summarise).
source
share