I have 10 data frames in the global environment- 5 with a name pattern and other 5 with another naming pattern. I want to put the dataframes with same naming pattern into a list each (two lists - one for each pattern) so ultimately I can run checks on each of them using lapply like this :
lapply(listofdataframes, function(x) range(x[ , "date"]))` The naming patterns are thus - Pattern 1 : q32013local, q42013local, q12014local, etc.
Pattern 2 : q32013national, q42013national etc.
I have used this in the past:
Filter(function(x) is(x, "data.frame"), mget(ls()))` but it obviously makes a list of all data frames in global environment.
I was looking for how to use grep and ls together . I found the bash equivalent questions for it on SO here List files with certain extensions with ls and grep but no R equivalent. I did refer these two related questions but they are quite different :
Return elements of list as independent objects in global environment , How can I make a list of all dataframes that are in my global environment?
localandnationaland split on thosemget(ls(pattern="q\\d+local")), but why do you needgrep(not tested yet)