R语言中mode和class的区别

 

mode:表示对象在内存中的存储类型。

class:表示的是变量的数据类型。

 

> a <- 1:10
> mode(a)                ## 内存中存储为数值
[1] "numeric"
> class(a)               ## 变量类型为整数
[1] "integer"
> b <- letters[1:10]
> mode(b)                ## 字符
[1] "character"
> class(b)               ## 字符
[1] "character"
> dat <- data.frame(a, b)    ## 数据框
> dat
    a b
1   1 a
2   2 b
3   3 c
4   4 d
5   5 e
6   6 f
7   7 g
8   8 h
9   9 i
10 10 j
> mode(dat)                  ## 内存中存储为list
[1] "list"
> class(dat)                 ## 变量类型为数据框
[1] "data.frame"

 

posted @ 2022-05-15 19:55  小鲨鱼2018  阅读(600)  评论(0编辑  收藏  举报