R 对象如何成为 typeof 列表并且还返回 is.data.frame true ?

Kei*_*son 1 r

我有一个名为 xCategories 的 R 对象

> xCategories

    code frequency percentage
1      1        75 12.3762376
2      1        75 12.3762376
3      1        75 12.3762376
4      1        75 12.3762376
5      1        75 12.3762376
6      2         0  0.0000000
7      2         0  0.0000000
8      2         0  0.0000000
9      3         8  1.3201320
10     3         8  1.3201320
11     3         8  1.3201320
12     3         8  1.3201320
Run Code Online (Sandbox Code Playgroud)

当我检查它是什么类型的对象时,答案是列表

> typeof(xCategories)
[1] "list"
Run Code Online (Sandbox Code Playgroud)

当我检查对象是否是数据框时......答案是正确的

> is.data.frame(xCategories)
[1] TRUE
Run Code Online (Sandbox Code Playgroud)

R 对象如何成为 typeof 列表并且还返回 is.data.frame true ?

李哲源*_*李哲源 5

因为data.frame是“类”,而有“模式” listclass您可能需要了解和之间的区别mode。注意,typeof返回modestorage.mode。这些文档将为您提供帮助?class,,?mode?typeof