[R] Filtering a dataframe

Eric Berger er|cjberger @end|ng |rom gm@||@com
Mon May 17 16:49:56 CEST 2021


If your data frame is named x then

y <- x[ x$id %in% c(1,2), ]

would create a new data frame y that has what you want.


On Mon, May 17, 2021 at 5:33 PM Admire Tarisirayi Chirume <
atchirume using gmail.com> wrote:

> Can someone help on how to filter my data frame below such that it retains
> a country if a given id (last column) is satisfied eg filtering a data
> frame that has countries with id 1 and 2 only
>
> Country year bank_ratio Reserve_ratio broad_money id
> Angola 2006 24 77 163 1
> Angola 2007 25 59 188 1
> Botswana 2008 38 64 317 2
> Botswana 2009 34 65 361 2
> Zimbabwe 2010 42 57 150 3
> Zimbabwe 2006 49 86 288 3
>
>
>
> Alternative email: addtarris using icloud.com/TChirume using rbz.co.zw
> Skype: admirechirume
> Call: +263773369884
> whatsapp: +818099861504
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list