我有一个列表,并希望将列表的元素分解为全局环境中的单独对象.
例如,我想要列表:
obj <- list(a=1:5, b=2:10, c=-5:5)
Run Code Online (Sandbox Code Playgroud)
是三个单独的对象a,b和c.
我尝试用以下方法实现这一点:
lapply(obj, FUN = function(x) names(x)[1] <<- x[1])
Run Code Online (Sandbox Code Playgroud)
但它失败了Error in names(x)[1] <<- x[1] : object 'x' not found.
我怎样才能实现目标?