[R] deleting rows with the same ID if any meet a condition
François Pinard
pinard at iro.umontreal.ca
Fri Apr 28 02:54:12 CEST 2006
[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
More information about the R-help
mailing list