Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typeof(data.frame) shows "list" in R [duplicate]

Tags:

r

attributes

Can someone clarify why typeof (data.frame) shows list in R? In contrast, class gives expected type. E.g., demonstrate that using the built-in data.frame mtcars.

> typeof(mtcars)
[1] "list"
> class(mtcars)
[1] "data.frame"

Any hints on how to use typeof versus class?

like image 336
Mark Tepeck Avatar asked Sep 01 '25 17:09

Mark Tepeck


1 Answers

data.frame and data.table are both collections (lists) of items (vectors, if you will), each item of the same length (ie each column is an item in the list, internally to R anyway). This is why unlike in a matrix, columns can have different classes.

Cheers.

like image 180
JVP Avatar answered Sep 04 '25 10:09

JVP