R语言 获取不同数据类型的类 – class() 函数 R语言中的 class() 函数是用来返回作为参数的数据类别的。 语法: class(x) 参数: x: 指定的数据 例子1 : # R program to illustrate # class function # Specifying "Biochemical oxygen demand" # data set x <- BOD x # Calling class() function class(x) RCopy 输出 Time demand 1 1 8.3 2 2 10.3 3 3 19.0 4 4 16.0 5 5 15.6 6 7 19.8 [1] "data.frame" RCopy 例2 : # R program to illustrate # class function # Calling class() function # over different types of data class(2) class(2.8) class("3") class("gfg") class(1 + 2i) RCopy 输出 [1] "numeric" [1] "numeric" [1] "character" [1] "character" [1] "complex" RCopy