R认为日期的向量是什么? [英] What does R think of vector of dates?

查看:107
本文介绍了R认为日期的向量是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但是我找不到答案很快,我太好奇了,即使迟到也不会放弃。

It's probably gonna be a stupid question, but I can't find the answer quickly and I'm too curious to give up even if late.

,为什么 1L:3L 字母都是向量

> is.vector(1:3)
[1] TRUE
> is.vector(letters)
[1] TRUE

x <- structure(1:3, class = "Date")
> is.vector(x)
[1] FALSE

?矢量

The atomic modes are "logical", "integer", "numeric" (synonym "double"),
"complex", "character" and "raw".

尽管 x 原子...

> is.atomic(x)
[1] TRUE

那么,不被读为矢量? (以 as.vector()的方式),这个区别背后有什么?

So, what makes a dates vector not to be read as vector? (in means of as.vector()) and what is there behind this difference?

这个问题来自于尝试使用 embed 与日期无关,因为它需要矢量或数组。但从结构上看,我看不到 1L:10L 结构(1L:10L,class =Date)之间的区别

This question comes from a try to use embed with dates which fails cause it wants vector or array. But from a structural point of view I can't see the difference between 1L:10L and structure(1L:10L, class="Date")

推荐答案

我的一些意见收集在一起回答:

A few of my comments collected together in an answer:

所以,文档还说:


is.vector返回TRUE,如果x是指定的向量模式没有名称以外的属性。否则返回FALSE。

is.vector returns TRUE if x is a vector of the specified mode having no attributes other than names. It returns FALSE otherwise.

所以在这个上面的答案, is.vector 更多像检查一个向量是否具有名称以外的属性,这当然可能不是很明显。

So as discussed in this pervious answer, is.vector is more like a check on whether a vector has attributes other than names, which certainly may not be obvious.

至于为什么 embed 行为的方式,我不知道。可能会使用 is.atomic ,但是您必须单独检查列表以实现相同的行为。可能还有一些我忽略的边缘案例。

As for why embed behaves the way it does, I'm not sure. It could potentially use is.atomic instead, but you'd then have to check for lists separately to achieve the same behavior. There may be some other edge cases I'm overlooking.

这篇关于R认为日期的向量是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆