3

Both class() and typeof() appear to return very similar outputs on some vectors and lists.

?typeof:

typeof determines the (R internal) type or storage mode of any object

and ?class

R possesses a simple generic function mechanism which can be used for an object-oriented style of programming. Method dispatch takes place based on the class of the first argument to the generic function.

In practice, what are the differences between the two?

stevec
  • 41,291
  • 27
  • 223
  • 311
  • This question has already been answered. Check https://stackoverflow.com/questions/35445112/what-is-the-difference-between-mode-and-class-in-r – kashj Jul 29 '20 at 06:45
  • 1
    Side note: I found this small chapter helpful: https://adv-r.hadley.nz/base-types.html – MKR Jul 29 '20 at 06:46
  • In practice, you'll be usually interested in the class on an object. – Roland Jul 29 '20 at 06:49
  • @Roland class() is what I use day to day, but tbh, I don’t think I’ve ever actually used typeof() – stevec Jul 29 '20 at 06:50
  • 1
    Me neither, I usually use `str(obj)`, `unclass(obj)` or `dput(obj)` to study the structure (and storage mode) of objects. However, I could imagine applications where I'd want to check the storage mode programmatically. – Roland Jul 29 '20 at 06:55

0 Answers0