R:确定表达的类型

时间:2015-03-06 03:33:43

标签: r types

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

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

t p 都是: is.numeric is.atomic 是。 vector ,而不是 is.list typeof double class numeric

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

1 个答案:

答案 0 :(得分:4)

要知道R中对象的类:

class(t)
class(p)

这两个对象共享同一个类numeric(它们实际上都是数字的向量,即使p是长度为1的向量)。

因此,为了区分它们,您应该使用length

length(t)
length(p)
相关问题