r - Converting character vector to list of data frames of same names -


i have set of data frames - let called report_001, report_002, report_003 , on - have names of them in character vector such as:

n <- c('report_001', 'report_002', 'report_003') 

i need turn list of data frames follows:

dflist <- list(report_001 = report_001, report_002 = report_002, report_003 = report_003) 

so can index this:

dflist[['report_002']] 

however, since have large number of data frames, don't want manually. trying this, has not worked:

dflist <- sapply(n, function(x) assign(x, as.name(x))) 

for question, data frames not important. keep things simple, can have:

report_001 <- mtcars report_002 <- mtcars report_003 <- mtcars 

how can achieve auto conversion of names of data frames list of data frames of same name indices?

report_001 <- mtcars report_002 <- mtcars report_003 <- mtcars n <- c('report_001', 'report_002', 'report_003') dflist <- mget(n) head(dflist[['report_001']]) #                    mpg cyl disp  hp drat    wt  qsec vs # mazda rx4         21.0   6  160 110 3.90 2.620 16.46  0  1 # mazda rx4 wag     21.0   6  160 110 3.90 2.875 17.02  0  1 # datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1 # hornet 4 drive    21.4   6  258 110 3.08 3.215 19.44  1  0 # hornet sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0 # valiant           18.1   6  225 105 2.76 3.460 20.22  1  0 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -