FailedMathematician
FailedMathematician

Reputation: 467

r list, self-created is different from loaded

I am following this tutorial. From which you can downloaded this data file (452 bytes only).

I explored the data structure of the data:

a busy cat

And then I tried to create the same type of data:

a busy cat

I have tried feeding in my own list but it didn't work the same way as the titanic.raw dataset. I Googled list and all of them look like my list but not like titanic.raw. They are both lists, I used is.list() to check.

Upvotes: 1

Views: 47

Answers (1)

gung - Reinstate Monica
gung - Reinstate Monica

Reputation: 11903

This is a confusion that is centered around the distinction between typeof() and class() in R. What you have is a data.frame, but typeof() will show "list". Consider:

> tr <- data.frame(a=1:5, b=letters[1:5])
> typeof(tr)
[1] "list"
> is.list(tr)
[1] TRUE
> class(tr)
[1] "data.frame"
> is.data.frame(tr)
[1] TRUE
> head(tr)
  a b
1 1 a
2 2 b
3 3 c
4 4 d
5 5 e
> tl <- list(a=1:5, b=letters[1:5])
> tl
$a
[1] 1 2 3 4 5

$b
[1] "a" "b" "c" "d" "e"

> typeof(tl)
[1] "list"
> is.list(tl)
[1] TRUE
> class(tl)
[1] "list"
> is.data.frame(tl)
[1] FALSE

For more information about class, typeof, and mode (another related function), see this excellent SO thread: A comprehensive survey of the types of things in R. 'mode' and 'class' and 'typeof' are insufficient

Upvotes: 1

Related Questions