Creating multiple media from a vector in R

I am having problems creating an environment in R. I understand that you can create a new environment, for example "Mar2015"=new.env(). It works. However, I cannot do this from a vector for some odd reason. I am creating this vector test=c("Mar2015","Sep2013")and test[1]=new.env()not working.

I am sure that it is the same that I can use a unique command unique(c(test[1],"March2015"))and confirm that they are the same.

Can someone explain why this is so?

+4
source share
1 answer

When test[i] = new.env()you start, you try to save the environment in a row vector; since the environment is not a string, this code will throw an error.

You can create a named list of environments with test:

envs <- sapply(test, function(x) new.env())

or

envs <- setNames(replicate(length(test), new.env()), test)

envs$Mar2015 envs$Sep2013 envs[["Mar2015"]] envs[["Sep2013"]]. , , , , , , .

, :

for (x in test) assign(x, new.env())
+2

Source: https://habr.com/ru/post/1599584/


All Articles