[R] elegant way to remove cases with many different ids

Ivan Calandra ivan.calandra at univ-reims.fr
Fri Jan 23 11:09:36 CET 2015


Hi Alain,

I think you're looking for %in% (see ?'%in%' for the help page)

id.vector <- c(1,3)  ## here you define the values you want to select: 
x, y, z...
subset(df, id %in% id.vector)

HTH,
Ivan

--
Ivan Calandra, ATER
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calandra at univ-reims.fr
https://www.researchgate.net/profile/Ivan_Calandra

Le 23/01/15 10:50, D. Alain a écrit :
> Dear R-List,
>
> I have nested data with cases grouped by IDs and I want to remove all cases with specific IDs.
>
> something like
>
> df<-data.frame(id=c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5),var=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15))
>
> subset(df,id== 1 | id == 3)
>
> Having a very large dataset with many IDs to remove this solution leaves me to write quite a long list of "id == x | id == y | id == z ...". I wonder if there is a more elegant way to do this? I tried with "id = c(x,y,z)" but this did not give the proper result.
>
> Any suggestions? Thank you!
>
> Best wishes
>
> Alain
>
>
>   
>   
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list