我试图计算在图中标识线(x = y)下方和上方的点数。
plot(datatumor$ageChronologique, datatumor$ageMethylation,
xlab ="Chronological age", ylab= "DNAm age")
abline(0,1)
" ageChronologique"和" ageMethylation"是datatumor的两个测量变量。
提前致谢
答案 0 :(得分:1)
您可以将逻辑datatumor$ageChronologique < datatumor$ageMethylation
与sum
结合使用:
# above 45 degree line:
sum(datatumor$ageChronologique < datatumor$ageMethylation)
# below 45 degree line:
sum(datatumor$ageChronologique > datatumor$ageMethylation)
使用with
可能看起来更好一些:
# above 45 degree line:
with(datatumor, sum(ageChronologique < ageMethylation))
如果变量中缺少值(NAs),可以在sum
中包含na.rm = T参数以忽略这些:
sum(datatumor$ageChronologique > datatumor$ageMethylation, na.rm=T)