Re: [R] Delete rows in the data frame by limiting values in two columns

From: Erik Iverson <eriki_at_ccbr.umn.edu>
Date: Fri, 25 Jun 2010 14:05:56 -0500

> x=c('germany','poor italy','usa','england','poor italy','japan')
> y=c('Spain','germany','usa','brazil','england','chile')
> s=1:6
> z=3:8
> test=data.frame(x,y,s,z)
>
> #Now I only concern the countries ('germany','england','brazil'). I would
> like to keep the rows where these three countries
> #are involved either in test$x OR test$y. So the result should be like as
> follows (I did this manually >< ):
>
> x y s z
> 1 germany Spain 1 3
> 2 poor italy germany 2 4
> 3 england Brazil 4 6
> 4 poor italy england 5 7
>
> Any codes work for this?

ss <- c("germany", "england", "brazil")
subset(test, x %in% ss | y %in% ss)



R-help_at_r-project.org mailing list
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. Received on Fri 25 Jun 2010 - 19:10:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jun 2010 - 19:40:34 GMT.

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

list of date sections of archive