Skip to content
Back to formatted view

Raw Message

Message-ID: <6B7EE504-3689-4EEA-86E7-BC20600FA387@comcast.net>
Date: 2013-01-18T21:47:26Z
From: David Winsemius
Subject: select rows with identical columns from a data frame
In-Reply-To: <50F9B85C.2000302@sapo.pt>

On Jan 18, 2013, at 1:02 PM, Rui Barradas wrote:

> Hello,
> 
> Try the following.
> 
> complete.cases(f) & apply(f, 1, function(x) all(x == x[1]))
> 
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Em 18-01-2013 20:53, Sam Steingold escreveu:
>> I have a data frame with several columns.
>> I want to select the rows with no NAs (as with complete.cases)
>> and all columns identical.
>> E.g., for
>> 
>> --8<---------------cut here---------------start------------->8---
>>> f <- data.frame(a=c(1,NA,NA,4),b=c(1,NA,3,40),c=c(1,NA,5,40))
>>> f
>>    a  b  c
>> 1  1  1  1
>> 2 NA NA NA
>> 3 NA  3  5
>> 4  4 40 40
>> --8<---------------cut here---------------end--------------->8---

> f[ which( rowSums(f==f[[1]]) == length(f) ), ]
  a b c
1 1 1 1

>> 
>> I want the vector TRUE,FALSE,FALSE,FALSE selecting just the first
>> row because there all 3 columns are the same and none is NA.
>> 
>> thanks!
>> 

David Winsemius
Alameda, CA, USA