对象创建时间戳 [英] Object creation timestamp
本文介绍了对象创建时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法检索对象的创建时间?
解决方案
一般情况下,您可以通过以下方式为自己创建的对象执行此操作
R>df <- data.frame(a=sample(LETTERS[1:5],10,TRUE),b=runif(10))R>attr(df, "createdAt") <- Sys.time()R>df乙1 乙 0.84370212 D 0.86834463 乙 0.51947914 乙 0.04804055 乙 0.56049786 C 0.19381547 0.14510778 D 0.17854059 C 0.393779510 乙 0.2874135R>字符串(df)'data.frame':10 个观察.2个变量:$ a:具有 4 个级别A"、B"、C"、D"的因子:2 4 2 2 2 3 1 4 3 2$ b: 数字 0.844 0.868 0.519 0.048 0.56 ...- attr(*, "createdAt")= POSIXct,格式:"2011-03-16 10:42:10.137434"R>
然后您可以自己编写一些使用该属性的自定义 print()
或 show()
函数.Frank Harrell 的 rms 和它的前身设计已经做了很长时间了.>
Is there a way to retrieve the time an object was created at?
解决方案
Not generally but you can do it for objects you create yourself via
R> df <- data.frame(a=sample(LETTERS[1:5],10,TRUE),b=runif(10))
R> attr(df, "createdAt") <- Sys.time()
R> df
a b
1 B 0.8437021
2 D 0.8683446
3 B 0.5194791
4 B 0.0480405
5 B 0.5604978
6 C 0.1938154
7 A 0.1451077
8 D 0.1785405
9 C 0.3937795
10 B 0.2874135
R> str(df)
'data.frame': 10 obs. of 2 variables:
$ a: Factor w/ 4 levels "A","B","C","D": 2 4 2 2 2 3 1 4 3 2
$ b: num 0.844 0.868 0.519 0.048 0.56 ...
- attr(*, "createdAt")= POSIXct, format: "2011-03-16 10:42:10.137434"
R>
and you can then write yourself some custom print()
or show()
functions that use the attribute. Frank Harrell's rms and its Design predecessor have done something like that for a long time.
这篇关于对象创建时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文