本文介绍了如果特定列中的值小于另一列中的值,则仅选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用R,并且需要选择年龄(死亡年龄)小于或等于漆膜(泌乳期)的行.我试图创建一个新的数据框,使其仅包含行/id,从而使"aged"列的值小于其相应的"laclength"值.
I am using R and need to select rows with aged (age of death) less than or equal to laclen (lactation length). I am trying to create a new data frame to only include rows/ids whereby the value of column'aged' is less than its corresponding 'laclength' value.
df:
id1 id2 laclen aged
9830 64526 26 6
7609 64547 28 0
9925 64551 3 0
9922 64551 3 5
9916 64551 3 8
9917 64551 3 8
9914 64551 3 2
新数据框应如下所示:
dfnew:
id1 id2 laclen aged
9830 64526 26 6
7609 64547 28 0
9925 64551 3 0
9914 64551 3 2
任何帮助将不胜感激!
Bazon
推荐答案
df[df$aged <= df$laclen, ]
应该做到这一点.方括号使您可以根据逻辑表达式进行索引.
Should do the trick. The square brackets allow you to index based on a logical expression.
这篇关于如果特定列中的值小于另一列中的值,则仅选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!