1、attach()
假设data.frame包含列name,age
attach(onedata.frame)后就可以引用直接引用onedata.frame中的元素了,例如:
(1)创建测试数据框
> name<-c("Zhangshan","Lisi","Wangwu","Zhaoliu")
> age<-c(20,30,40,50)
> onedata.frame<-data.frame(name,age)
> onedata.frame
name age
1 Zhangshan 20
2 Lisi 30
3 Wangwu 40
4 Zhaoliu 50
(2)attach测试
> attach(onedata.frame)
The following objects are masked _by_ .GlobalEnv:
age, name
> age
[1] 20 30 40 50
> name
[1] "Zhangshan" "Lisi" "Wangwu" "Zhaoliu"
> detach(onedata.frame)
> name
错误: 找不到对象'name'
可见,访问数据框中的元素只在命令attach()和detach()之间可以搜索到。
---------------------
作者:hongweigg
来源:CSDN
原文:https://blog.csdn.net/hongweigg/article/details/48093577
版权声明:本文为博主原创文章,转载请附上博文链接!