R change name of dataset with stored string -


i'm creating lots of datasets loop , need make sure these different datasets named , stored in workspace. question following. let's have dataset (here airquality), want create 4 datasets , store them in workspace

split dataset

airquality$n<-letters[airquality$month] head(airquality) alldatasets<-split(airquality,airquality$n) names(alldatasets) 

now want extract each dataset loop, example

#conceptual loop (i in (1:names(alldatasets))){ #create  dataset  alldatasets[i] , name    names(alldatasets)[i]   } 

so after loop can work each dataset (e, f, g, h, i) separately ( don't want apply same function datasets, want store each single 1 independently in workspace). suppose question doesn't apply loops, it's how rename dataset (not columns) name stored in string.

you can use list2env().

list2env(alldatasets, .globalenv) 

now e, f, g, h , i available in workspace (global environment in case, can specify different environment in second argument if like).


to assign name string can use assign(). e.g. in response marco's comment below:

d <- data.frame(rnorm(1:10), rnorm(1:2)) name <- 'thatone' assign(name, d) 

or directly string:

assign('thatone', d) 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -