[R] Re moving redundant observations

chi.yau chimingyau at gmail.com
Fri Sep 4 02:36:50 CEST 2009



Try this:

# input data
ID <- scan()
  1 1 1 1 2 2 2 2 2

V2 <- scan()
  23.9 NA 22.0 23.9 0.4 NA NA 3.0 2.4

# setup data frame
DF <- cbind(ID, V2); DF

# find unique pairs
unique(DF)



###############
# Chi Yau
# http://r-tutor.com
###############



Barbara-43 wrote:
> 
> Hello R-helpers,
> 
> I am having a difficult time figuring out the following: I have a data 
> frame with 24 variables. I need to remove redundant observations where, 
> within the same values of ID, V2 is equal to another observation in V2.
> 
>  >ID  V2  
>  >1    23.9
>  >1    NA
>  >1    22.0
>  >1   23.9
>  >2   0.4
>  >2  NA
>  >2  NA
>  >2  3.0
>  >2  0.4
> 
> Thus, the new data frame would look like this (plus the other 22
> variables):
> 
>  >ID  V2  
>  >1    23.9
>  >1    NA
>  >1    22.0
>  >2   0.4
>  >2  NA
>  >2  3.0
> 
> Thank you in advance,
> Barb
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/Removing-redundant-observations-tp25286208p25286405.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list