0

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?

Metrics
  • 15,172
  • 7
  • 54
  • 83
L D
  • 593
  • 1
  • 3
  • 16
  • 1
    You want to find that `p` is numeric and `t` is a vector of numeric? –  Mar 06 '15 at 03:36
  • 1
    See http://stackoverflow.com/questions/6258004/r-types-and-classes-of-variables?rq=1 – Benjamin Mar 06 '15 at 03:36
  • 1
    @Benjamin Good reference but I am not sure that helps here: `class`, `mode` and `typeof` return always the same value for `t` and `p`. – RockScience Mar 06 '15 at 03:41
  • 2
    It might be helpful for you to know that there is no "scalar" data type in R. Everything is a vector, and "single numbers" are also stored internally as a vector of length one. So `p` and `t` really are the same type of thing, they differ only in length. – joran Mar 06 '15 at 04:09

1 Answers1

4

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)
RockScience
  • 17,932
  • 26
  • 89
  • 125