How can I access all objects of class data.frame inside .GlobalEnv in R

后端 未结 4 842
醉话见心
醉话见心 2021-01-25 03:12

I have 8,000 data.frames inside my global environment (.GlobalEnv) in R, for example

head(ls(.GlobalEnv))
#[1] \"db1\" \"db2\" \"db3\"          


        
4条回答
  •  庸人自扰
    2021-01-25 04:02

    I have found another solution:

    db1 <- data.frame(x = c(1,2,3),y = c(1.1,1.2,1.3))
    db2 <- data.frame(x = c(1,2,3,4),y = c(2,2.1,2.2,2.3))
    db3 <- data.frame(x = c(1,2,3,4,5),y = c(3,3.1,3.2,3.3,3.4))
    ls()
    #[1] "db1" "db2" "db3"
    nombres <- ls()
    eval(parse(text = nombres[1]))
    #  x   y
    #1 1 1.1
    #2 2 1.2
    #3 3 1.3
    lm(y~x,data = eval(parse(text = nombres[1])))
    

    Thanks!

提交回复
热议问题