try this. Splits the dataframe based on the two IDs and then chooses
the first one in cases where condition not met.
> id1<-c(1,1,2,2,3,3,4,5,5,6,6,7,8,9,9,10)
> id2<-c(22,22,34,34,15,15,76,45,45,84,84,37,52,66,66,91)
> GENDER<-sample(c("G-UNK","G-M","G-F"),16, replace = TRUE)
> ETH <-sample(
G-F E-AF
#7 7 37 G-F E-AF
#8 8 52 G-F E-AF
#9 9 66 G-F E-AF
#10 10 91 G-F E-VT
A.K.
- Original Message -
From: arun
To: Robert Lynch
Cc: R help
Sent: Saturday, September 7, 2013 11:30 AM
Subject: Re: [R] finding both rows that are duplicated in a data frame
Hi,
example<- data.frame(id1,id2,GENDER,ETH,stringsAsFactors=FALSE)
res<-unique(example[!(grepl("UNK",example$GENDER)|grepl("UNK",example$ETH)),])
res
# id1 id2 GENDER ETH
#1 1 22 G-M E-VT
#3 2 34 G-M E-AF
#5 3 15 G-M E-AF
#7 4 76 G-F E-VT
#8 5 45 G-F E-VT
#
3 matches
Mail list logo