There are several columns in my data frame:
df1 <- data.frame(A = c(1,2,4), B=c(1,3,1), C=c(1,1,3))
I have two conditions for getting average values ββfor column A.
- Condition 1: I want to get the average value of column A when B is 1, that is, only rows 1 and row 2 will be averaged.
- Condition 2: I want to get the average value of column B when the values ββof column A are greater than 1 but less than 3, i.e. only line 2 will be considered.
I know that I can use a filter to crop a data frame only for column B = 1. However, I'm not sure how to do this when I want column B to be considered a range between 1 and 3.
Are there any smarter ways to get average column values ββwithout first reducing the framework to a smaller size?
source share