好吧,至于帮助入门,该which
功能会有所帮助。它返回满足特定条件的索引 - 因此要查看列“1”大于 58 的所有行,您可以使用:
matched.indices <- which(L[,"1"] > 58)
然后要找到所有低 5 行的索引,我们可以简单地添加 5:
shifted.indices <- matched.indices + 5
从这里,您可以根据需要打印出成对的值和坐标。一种方法如下:
len <- length(matched.indices)
cat(paste(rep("[",len), matched.indices, rep(",1],", len), # 1st coordinate
rep("[",len), shifted.indices, rep(",4] = ", len), # 2nd coordinate
L[matched.indices, "1"], # 1st value
rep(",", len),
L[shifted.indices, "4"], # 2nd value
sep=""),sep="\n")
输出将如下所示:
[4,1],[9,4] = 58.9223792285318,48.5241852967192
[70,1],[75,4] = 58.5015984791419,55.3071097158975
[76,1],[81,4] = 61.7996739529131,51.6725968541657
[85,1],[90,4] = 58.0881601753751,40.2410431328713
[92,1],[97,4] = 58.1622310810397,50.6118549434608
[96,1],[101,4] = 58.4433975051732,NA
正如我所说,这只是一个开始。具体来说,您没有提到如何处理最后 5 行;我的解决方案只会为这些值打印 NA(与上面的最后一行一样)。如果您想澄清这一点,我将相应地更新答案。