2.1 类型

x <- "abc" # 数据对象
typeof(x) # 数据类型
## [1] "character"
mode(x) # 存储模式
## [1] "character"
storage.mode(x) # 存储类型
## [1] "character"
表 2.1: 函数 typeof() 返回的数据类型 5
符号 含义
NULL 空值
symbol 可变的名称/变量
pairlist pairlist 对象***
closure 函数闭包
environment 环境
promise 实现惰性求值的对象
language R 语言构造
special 内部函数,不计算参数
builtin 内部函数,计算参数
char scalar 型字符对象***
logical 逻辑向量
integer 整数向量
double 实值向量
complex 复值向量
character 字符向量
... 可变长度的参数***
any 匹配任意类型
expression 表达式对象
list 列表
bytecode 位代码***
externalptr 外部指针对象
weakref 弱引用对象
raw 位向量
S4 S4 对象
表 2.2: R/Rcpp 提供的基本数据类型
Value R vector Rcpp vector Rcpp matrix Rcpp scalar C++ scalar
Logical logical LogicalVector LogicalMatrix - bool
Integer integer IntegerVector IntegerMatrix - int
Real numeric NumericVector NumericMatrix - double
Complex complex ComplexVector ComplexMatrix Rcomplex complex
String character CharacterVector (StringVector) CharacterMatrix (StringMatrix) String string
Date Date DateVector - Date -
Datetime POSIXct DatetimeVector - Datetime time_t

  1. 表格中带 *** 标记的类型,用户不能轻易获得↩︎