【问题标题】:Manage objects in the global environment in R在 R 中管理全局环境中的对象
【发布时间】:2018-10-27 05:05:13
【问题描述】:

这是我的 RStudio 版本。

rstudioapi::versionInfo()
$version
[1] ‘1.1.447’

我发现在右上角,我可以得到全局环境中所有对象的信息。 在grid模式下,我可以做一些dplyr的样式功能,比如filterarrange

有什么办法可以将这些信息放入数据框中,以便我可以通过dplyr 对其进行操作。

【问题讨论】:

    标签: r dplyr rstudio


    【解决方案1】:

    您可以使用类似...的内容来近似 RStudio 的环境选项卡中的信息。

    data(iris)
    data(mtcars)
    x <- 1:3
    y <- "yes"
    
    ls_vec <- ls()
    ls_list <- vector('list', length(ls_vec))
    for (i in seq_along(ls_vec)) {
      ls_list[[i]] <-
        data.frame(
          Name = deparse(ls_vec[i]),
          Type = class(get(ls_vec[i])),
          Length = length(get(ls_vec[i])),
          Size = format(object.size(get(ls_vec[i])))
        )
    }
    
    Reduce(rbind, ls_list)
    #        Name       Type Length       Size
    # 1       "i"    integer      1   56 bytes
    # 2    "iris" data.frame      5 7256 bytes
    # 3 "ls_list"       list      7 5064 bytes
    # 4  "ls_vec"  character      7  504 bytes
    # 5  "mtcars" data.frame     11 7208 bytes
    # 6       "x"    integer      3   64 bytes
    # 7       "y"  character      1  112 bytes
    

    【讨论】:

    • 感谢分享,我复制过来写一个自定义函数。
    猜你喜欢
    • 2019-12-16
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 2017-12-30
    • 2015-03-27
    相关资源
    最近更新 更多