子行具有相同值的列范围

时间:2016-09-20 08:25:26

标签: r subset

在R中有数据框:

entity TwotoOne is
PORT 
(
  w0, w1, s  : IN STD_LOGIC;
  f       : OUT STD_LOGIC
);

end TwotoOne;

architecture Dataflow of TwotoOne is
BEGIN

  f <= ((not s) and w0) or (s and w1); 

END Dataflow ; 

我想提取列 one two three four 1 A A Z Z 2 A A A Z 3 A A A A 4 Z A A A 5 A A A A 中行至少有一个Z的子集。那就是:

two : four

1 个答案:

答案 0 :(得分:0)

我们可以在逻辑矩阵上使用rowSums(从删除第一列(df[-1]并比较(==)和"Z")来提取行

df1[rowSums(df1[-1]=="Z")>0,]
#  one two three four
#1   A   A     Z    Z
#2   A   A     A    Z