對於給定dt
我想通過比較另一列來計算某些特定行。R:基於邏輯檢查對行進行計數(<0 & > 0)
這裏是我的意思;
library(data.table)
dt <- data.table(a=c(0.98,-0.97,0.95,-0.92,-0.82,-0.7,0.6,-0.8,0.4,0.92),b=c(0.98,-0.92,-0.94,0.91,-0.90,0.7,-0.67,-0.62,-0.66,0.84))
#> dt
# a b
# 1: 0.98 0.98
# 2: -0.97 -0.92
# 3: 0.95 -0.94
# 4: -0.92 0.91
# 5: -0.82 -0.90
# 6: -0.70 0.70
# 7: 0.60 -0.67
# 8: -0.80 -0.62
# 9: 0.40 -0.66
#10: 0.92 0.84
我只想計算條件> 0 & b < 0的情況。所以計數應3
@VincentBonhomme除您的解決方案。謝謝! – Alexander