0

Python has the type function which tells you if something is a list, numpy array or a string etc. That is, it tells you the class of the object. However, R seems to have just typeof and class functions that tell you what the internal data type is - say, it gives double when I do typeof(array(1,2)), and it gives list when I do typeof(list(1,'a')). My questions are:

  1. What exactly do typeof and class do? Why don't I get array and list above, or integer and integer/character? Moreover, where do these two methods differ?
  2. What if I want to know what the type of object at hand is - i.e. is it a list? A matrix? An array (in the case above)? A string? Is there a way to do this other than doing something like referring to each specific one in a way such as is.array (not sure if that's a thing even)?
algebroo
  • 132
  • 6
  • I may be completely off, but is it for S4 objects that they have a class attribute? – algebroo Jun 30 '22 at 15:55
  • If you want to check for a class for an object `x` `"myclass" %in% class(x)` is a good option because objects can have multiple classes. – MrFlick Jun 30 '22 at 16:06

0 Answers0