Error in R with list2env function

Posted on

Question :

I try to convert my list (which contains 12 dataframes and approximately 20,000 lines each) into separate dataframes:


but the following error message appears:

names(x) must be a character vector of the same length as x

What can it be and what to do?


Answer :

As noted by @RuiBarradas, the list should be named so that it can be transformed into an environment.

Reproducing the error:

mylist <- list(1, 2, "a")
# Error in list2env(mylist, envir = .GlobalEnv) : 
#   names(x) deve ser um vetor de caracter de mesmo comprimento que x

Applying the solution we have

names(mylist) <- paste("membro", seq_along(mylist), sep = ".")
# [1] "mylist"
# <environment: R_GlobalEnv>
# [1] "membro.1" "membro.2" "membro.3" "mylist" 


Leave a Reply

Your email address will not be published. Required fields are marked *