【问题标题】:The attached object won't change when I modify it?当我修改它时,附加的对象不会改变?
【发布时间】:2014-02-02 14:57:03
【问题描述】:

重现问题的代码:

创建一个包含一列“a”的数据框。

dataObj=data.frame(a=1) 
> dataObj
  a
1 1


附加数据对象

attach(dataObj) 
> a
[1] 1


修改dataObj,但是a的值不变。

dataObj[1,"a"]=3
> a
[1] 1

【问题讨论】:

    标签: r


    【解决方案1】:

    来自?attach

    The database is not actually attached. Rather, a new environment is created on
    the search path and the elements of a list (including columns of a data frame)
    or objects in a save file or an environment are copied into the new environment.
    

    将副本添加到搜索路径,而不是对象本身。修改原件时,副本不变。

    建议(许多人)避免使用attachwith 是一个方便的替代品。

    【讨论】:

    猜你喜欢
    • 2013-12-09
    • 2020-03-03
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 2015-01-30
    • 1970-01-01
    相关资源
    最近更新 更多