Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们都知道诸如is.data.frame或之类的功能is.double。可能很容易做,但很难用谷歌搜索:如何创建自己的。?功能?那么有没有更好的方法来做到这一点:
is.data.frame
is.double
is.myClass <- function(x){ if(class(x) %in% "myClass") return(TRUE) else return(FALSE) }
也许inherits就足够了:
inherits
is.myClass <- function(x) {inherits(x,"myClass")} x <- 1 is.myClass(x) [1] FALSE class(x) <- c(class(x),"myClass") is.myClass(x) [1] TRUE