I have a data frame like this:
df
A B
[1,] 1 4
[2,] 2 3
[3,] 3 5
[4,] 4 7
[5,] 5 5
[6,] 6 7
[7,] 7 4
[8,] 8 7
[9,] 9 3
[10,] 10 7
I need to sum the numbers in column B that fall between a certain interval defined by column A. For example sum the value in B between A≥1 and A<3.
I'm trying to use this:
> sum(which(df$B[df$A>=1] & df$B[df$A<3]))
but it does not give me what I want.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…