R:确定表达式类型

R: Determine type of expression

我如何确定 R 中变量的类型?

t <- seq(from=0, to=10, by=2)
p <- 2

tp 都是:is.numeric, is.atomic, is.vector, 不是 is.list, typeof double, class numeric.

如何确定p只是一个数字而t是更多的东西?

要了解 R 中对象的 class:

class(t)
class(p)

这2个对象共享相同的class numeric(它们实际上都是数值向量,即使p是长度为1的向量)。

所以要区分它们你应该使用 length:

length(t)
length(p)