[R] Sequential Filtering of a Data Set

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Fri Apr 26 17:06:49 CEST 2019


Hello,

Something like this?

Map(function(y) {subset(tt2, year >= y)}, 2001:2018)

Or this?

mapply(function(y) {subset(tt2, year >= y)}, 2001:2018, SIMPLIFY = FALSE)


Hope this helps,

Rui Barradas

Às 15:51 de 26/04/19, Lorenzo Isella escreveu:
> Dear All,
> I must be drowning in a glass of water.
> Consider the following data set
> 
> tt2<-structure(list(year = c(2000, 2001, 2002, 2003, 2004, 2005, 2006, 
> 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018), 
> country = c("DE", "DE", "DE", "DE", "DE", "DE", "DE", "DE", "DE", "DE", 
> "DE", "DE", "DE", "DE", "DE", "DE", "DE", "DE", "DE"), berd = c(35600, 
> 36331.9, 36950, 38029, 38363, 38651.038, 41148, 43034, 46073, 45275, 
> 46929, 51077.2, 53790.1, 53566.2, 56996.5, 60952, 62826, 68644, NA)), 
> row.names = c(NA, -19L), class = c("tbl_df", "tbl", "data.frame"))
> 
> 
> I would like to obtain a list of it, where every element of the list
> contains the subset of tt2 for which year>=2000,
> year>=2001....year>=2018 etc...
> It seems something I can tackle with map or map2 from purrr, but so
> far I am banging my head against the wall.
> Anyone can help me?
> Regards
> 
> Lorenzo
> 
> ______________________________________________
> 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.



More information about the R-help mailing list