11

Well the question says it all..I want to check in one of my functions if a function parameter given is of xts or data frame type. How can I do this?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
MichiZH
  • 5,587
  • 12
  • 41
  • 81
  • 2
    class(YourX) is one way – user20650 Feb 19 '14 at 13:56
  • 2
    http://stackoverflow.com/questions/8855589/a-comprehensive-survey-of-the-types-of-things-in-r-mode-and-class-and-type, http://stackoverflow.com/questions/6258004/r-types-and-classes-of-variables, http://stackoverflow.com/questions/1177926/r-object-identification, http://stackoverflow.com/questions/21125222/determine-the-data-types-of-an-r-data-frames-columns – GSee Feb 19 '14 at 14:13

1 Answers1

21

It is a general practice to add is.smth and as.smth functions for these types of checks and conversions:

df <- data.frame()
xt <- xts()
is.data.frame(df)
[1] TRUE
is.data.frame(xt)
[1] FALSE
is.xts(df)
[1] FALSE
is.xts(xt)
[1] TRUE
tonytonov
  • 25,060
  • 16
  • 82
  • 98