Re: [R] deleting rows with the same ID if any meet a condition

From: François Pinard <pinard_at_iro.umontreal.ca>
Date: Fri 28 Apr 2006 - 10:54:12 EST

[gblevins]

>If x2 equal 2 then I want to delete all the rows for that person from
>the dataframe--see Before and After below.

>Before
>x1 <- c(1,1,1,2,2,3,3,3)
>x2 <- c(2,3,3,1,1,4,4,2)
>x3 <- data.frame(x1,x2)

>> x3
> x1 x2
>1 1 2
>2 1 3
>3 1 3
>4 2 1
>5 2 1
>6 3 4
>7 3 4
>8 3 2

>After
> x1 x2
>1 2 1
>2 2 1

You might try:

  subset(x3, !x1 %in% x1[which(x2==2)])

-- 
François Pinard   http://pinard.progiciels-bpi.ca

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Apr 28 10:58:51 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 28 Apr 2006 - 12:09:51 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.