L D
L D

Reputation: 623

R: Determine type of expression

how can i determine type of variable in R?

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

t and p are both: is.numeric, is.atomic, is.vector, not is.list, typeof double, class numeric.

How to determine that p is just only a number and that t is something more?

Upvotes: 0

Views: 101

Answers (1)

RockScience
RockScience

Reputation: 18620

To know the class of an object in R:

class(t)
class(p)

These 2 objects share the same class numeric (they are actually both vectors of numerics, even p is a vector of length 1).

So to differenciate them you should use length:

length(t)
length(p)

Upvotes: 4

Related Questions