楼主: zhengbo8
24131 8

[问答] 请问:typeof()、mode()、class()的区别? [推广有奖]

  • 0关注
  • 27粉丝

已卖:539份资源

教授

33%

还不是VIP/贵宾

-

威望
0
论坛币
9353 个
通用积分
4294.7362
学术水平
157 点
热心指数
173 点
信用等级
130 点
经验
66005 点
帖子
642
精华
0
在线时间
1976 小时
注册时间
2009-10-6
最后登录
2025-12-14

初级热心勋章

楼主
zhengbo8 发表于 2013-8-18 17:57:39 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
RT。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:mode type Mod ODE

沙发
webgu 发表于 2013-8-19 11:12:30
R的这个类型确实有些不好理解。
我的粗略的理解:
mode是R存诸对象的类型, class 的概念是沿袭面向对象编程的概念而来,是一个更抽象的概念。typeof 和mode 相似,但是好像比mode分得更精细。

从精细度上说,typeof>mode>class.

对R了解不多,不一定对。
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

藤椅
zhengbo8 发表于 2013-8-19 18:47:37
还是感谢版主大人了!

板凳
童小军 发表于 2013-8-20 22:58:38
mode():模式,常见的有"logical", "integer", "double", "complex", "raw", "character", "list", "expression", "name", "symbol" and "function".
class():类,In R every 'object' has a mode and a class.

Modes have the same set of names as types (see typeof) except that
  • types "integer" and "double" are returned as "numeric".
  • types "special" and "builtin" are returned as "function".
  • type "symbol" is called mode "name".
  • type "language" is returned as "("  or  "call".
    from:?mode()
    也可以参考:http://stackoverflow.com/questio ... -and-class-and-type

    我这里用个因子例子来说明,希望能讲清楚
    > gl(2,5)            #新建一个因子
    [1] 1 1 1 1 1 2 2 2 2 2
    Levels: 1 2
    > class(gl(2,5))   #查看变量的类,显示为因子;
    [1] "factor"
    > mode(gl(2,5))     #查看数据大类,显示为数值型;
    [1] "numeric"
    > typeof(gl(2,5))    #查看数据细类,显示为整数型;
    [1] "integer"
    来自:http://f.dataguru.cn/thread-99785-1-1.html




报纸
童小军 发表于 2013-8-20 22:59:08

我这里用个因子例子来说明,希望能讲清楚
> gl(2,5)            #新建一个因子
[1] 1 1 1 1 1 2 2 2 2 2
Levels: 1 2
> class(gl(2,5))   #查看变量的类,显示为因子;
[1] "factor"
> mode(gl(2,5))     #查看数据大类,显示为数值型;
[1] "numeric"
> typeof(gl(2,5))    #查看数据细类,显示为整数型;
[1] "integer"
来自:http://f.dataguru.cn/thread-99785-1-1.html

地板
webgu 发表于 2013-8-21 08:22:29
zhengbo8 发表于 2013-8-19 18:47
还是感谢版主大人了!
都开始折腾R了。
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

7
@http://-第七地 在职认证  发表于 2014-7-3 09:50:43
[img][/img]

8
flamingstone 发表于 2014-7-3 20:15:49
看以下输出结果:

> df=data.frame(c1=letters[1:3], c2=1:3, c3=c(1,-1,3.0), stringsAsFactors=F)
> sapply(df, mode)
         c1          c2          c3
"character"   "numeric"   "numeric"
> sapply(df, class)
         c1          c2          c3
"character"   "integer"   "numeric"
> sapply(df, typeof)
         c1          c2          c3
"character"   "integer"    "double"

可以发现,在展现数据的细节上,mode<class<typeof。

9
ineedfabulous12 发表于 2019-2-23 22:42:18
'mode' is a mutually exclusive classification of objects according to their basic structure. The 'atomic' modes are numeric, complex, character and logical. Recursive objects have modes such as 'list' or 'function' or a few others. An object has one and only one mode.

'class' is a property assigned to an object that determines how generic functions operate with it. It is not a mutually exclusive classification. If an object has no specific class assigned to it, such as a simple numeric vector, it's class is usually the same as its mode, by convention.

Changing the mode of an object is often called 'coercion'. The mode of an object can change without necessarily changing the class. e.g.

这个答案参见下面这个网页的第2个回答 我觉得说得比较好https://stackoverflow.com/questions/35445112/what-is-the-difference-between-mode-and-class-in-r
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
admin_kefu + 50 + 5 + 5 + 5 热心帮助其他会员

总评分: 论坛币 + 50  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 23:11