R: Put Variables from .GlobalEnv, that meet certain criteria in list -


for weeks measured data once week. since measuring instrument used elsewhere in between got quite few .csv-files read r , got them in workspace now. named them alike of data.frames contain pattern "11." in variable name. know can list of (only) variable names using

ls(pattern = "11.") 

but want have list containing data.frames. of course go in script , change read.table command e.g.

a.11.01 <- read.table(...) 

to

data.list[1] <- read.table(...) 

and later change name of list element data.list[1] "a.11.01" (and have saved nice amount of time if had done immediately) , i'm quite sure find out how defining , naming of list element in 1 command, feels if there quite simple option let r create list @ all.

(another approach tried data.list[1] <- .globalenv[1], ended finding no way subset environment. (my other approaches seem silly mentioned @ all.))

you use

mylist <- mget(ls(pattern = "11."))  

or, if want make sure data.frames pattern (not other objects) use

mylist <- filter(is.data.frame, mget(ls(pattern = "11."))) 

by way, in situation, have been easy read them list directly using like

listfiles <- list.files("path/to/folder", pattern = "\\.csv$", full.names=true) mylist <- lapply(listfiles, read.csv, stringsasfactors = false) 

(stringsasfactors = false example show you can add other arguments)


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -