R语言中attr()函数

 

attr()函数允许你创建任意属性并将其与对象关联。

 

1、

复制代码
> a <- 1:5
> b <- letters[1:5]
> c <- LETTERS[1:5]
> dat <- data.frame(a, b, c)
> dat                              ## 测试数据框
  a b c
1 1 a A
2 2 b B
3 3 c C
4 4 d D
5 5 e E
> attributes(dat)                 ## 查看全部属性
$names
[1] "a" "b" "c"

$class
[1] "data.frame"

$row.names
[1] 1 2 3 4 5

> attr(dat, "tag")                 ## 查看指定属性
NULL
> attr(dat, "tag") <- "this is a test!"      ## 添加新属性tag
> attributes(dat)                            ## 查看全部属性
$names
[1] "a" "b" "c"

$class
[1] "data.frame"

$row.names
[1] 1 2 3 4 5

$tag
[1] "this is a test!"

> attr(dat, "tag")                          ## 查看指定属性
[1] "this is a test!"
复制代码

 

参考:https://blog.csdn.net/sinat_40586658/article/details/120442829

 

posted @   小鲨鱼2018  阅读(2058)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示