[R] Keep rows in a dataset if one value in a column is duplicated
GradStudentDD
dd7kc at virginia.edu
Thu Sep 27 21:46:14 CEST 2012
Hi,
I have a data set of observations by either one person or a pair of people.
I want to only keep the pair observations, and was using the code below
until it gave me the error " $ operator is invalid for atomic vectors". I am
just beginning to learn R, so I apologize if the code is really rough.
Basically I want to keep all the rows in the data set for which the value of
"Pairiddups" is TRUE. How do I do it? And how do I get past the error?
Thank you so much,
Diana
PairID<-c(Health2$pairid)
duplicated(PairID, incomparables=TRUE, fromLast=TRUE)
PairIDdup=duplicated(PairID)
cbind(PairID, PairIDdup)
PairID[which(PairIDdup)]
PairIDDuplicates<-PairID%in%PairID[which(PairIDdup)]
PairIDs<-cbind(PairID, PairIDDuplicates)
colnames(PairIDs)<-c("Pairid","Pairiddups")
Health2PairsOnly<-PairIDs[ which(PairIDs$Pairiddups=='TRUE'), ]
--
View this message in context: http://r.789695.n4.nabble.com/Keep-rows-in-a-dataset-if-one-value-in-a-column-is-duplicated-tp4644420.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list