Hi, I am doing a very simple job here.
I have 3 columns of data; a, b and c. I want to calculate the ratio of b and c when the value of b is greater than 5.
The code I use is as follows:
a <- c(1,2,3,4,5,6,7,8)
b <- c(2,4,5,8,10,12,15,18)
c <- c (10,9,8,15,31,12,13,12)
df <- data.frame(a,b,c)
df$d <- with(df,b/c)
I calculated the ratio, but could not use the condition. I know it is trivial, but it takes a lot of time. I appreciate your help.
source
share