在R中检查对象类的首选方法 [英] Preferred method of checking object's class in R
本文介绍了在R中检查对象类的首选方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在R中检查对象类的首选方法是什么?
What is the preferred method of checking an object's class in R?
(1)
is.data.frame(df)
p>
(2)
class(df) == 'data.frame'
(3)
'data.frame' %in% class(df)
推荐答案
我会说
inherits(df,"data.frame")
b $ b
或
or
is(df,"data.frame")
你的列表中的#2可能会失败,因为(如你在#3中建议的) class(df)
可以有长度> 1。( is.data.frame
很好,但不是所有类都有 code>方法:参见
方法(is)
)
among other things, #2 in your list can fail because (as you suggest in #3) class(df)
can have length > 1. (is.data.frame
is nice, but not all classes have is.
methods: see methods("is")
)
这篇关于在R中检查对象类的首选方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文