Aurelie Cosandey Godin
2011-Nov-06 14:11 UTC
[R] Deleting rows dataframe in R conditional to “if any of (a specific variable) is equal to”
Dear list, I have been struggling for some time now with this code... I have this vector of unique ID "EID" of length 821 extracted from one of my dataframe (skate). It looks like this:> head(skate$EID)[1] "896-19" "895-8" "899-1" "899-5" "899-8" "895-7" I would like to remove the complete rows in another dataframe (t5) if any of the t5$EID is equal (a duplicate) of skate$EID. I was able to get my 'duplicated' dataframe in t5 of all my matching EID as follow:> xx<-skate$EID > t5[match(xx,t5[,26]), ]#gives me a dataframe of all matching EID in skate$EIDrecord.t trip set month stratum NAFO unit.area time dur.set distance 8948 5 896 19 11 221 2J N12 908 15 8 8849 5 895 8 10 766 3O R36 1650 16 8 9289 5 899 1 12 743 3L V26 2052 15 8 9299 5 899 5 12 746 3L W27 1129 14 7 Where t5[,26] correspond to t5$EID column. I'm sure it's simple, but I'm not sure how to remove all of these now from my t5 dataframe! Tips would be very much appreciated! Thank you! Aurelie Cosandey-Godin Ph.D. student, Department of Biology Industrial Graduate Fellow, WWF-Canada Dalhousie University | Email: godina@dal.ca [[alternative HTML version deleted]]
Carl Witthoft
2011-Nov-06 16:47 UTC
[R] Deleting rows dataframe in R conditional to “if any of (a specific variable) is equal to”
Not too difficult. Rgames> bar<-c(3,5,7) Rgames> foo<-c(1,3,5,6,8,9,7) Rgames> match(bar,foo) [1] 2 3 7 # these are the matching positions Rgames> foo[-(match(bar,foo))] [1] 1 6 8 9 <quote> Dear list, I have been struggling for some time now with this code... I have this vector of unique ID "EID" of length 821 extracted from one of my dataframe (skate). It looks like this: > head(skate$EID) [1] "896-19" "895-8" "899-1" "899-5" "899-8" "895-7" I would like to remove the complete rows in another dataframe (t5) if any of the t5$EID is equal (a duplicate) of skate$EID. I was able to get my 'duplicated' dataframe in t5 of all my matching EID as follow: > xx<-skate$EID > t5[match(xx,t5[,26]), ]#gives me a dataframe of all matching EID in skate$EID record.t trip set month stratum NAFO unit.area time dur.set distance 8948 5 896 19 11 221 2J N12 908 15 8 8849 5 895 8 10 766 3O R36 1650 16 8 9289 5 899 1 12 743 3L V26 2052 15 8 9299 5 899 5 12 746 3L W27 1129 14 7 Where t5[,26] correspond to t5$EID column. I'm sure it's simple, but I'm not sure how to remove all of these now from my t5 dataframe! Tips would be very much appreciated! Thank you! Aurelie Cosandey-Godin Ph.D. student, Department of Biology Industrial Graduate Fellow, WWF-Canada Dalhousie University | Email: godina_at_dal.ca -- Sent from my Cray XK6 "Pendeo-navem mei anguillae plena est."