变量不需要声明,
常用的变量有:
变量类型 | 定义 | 例子 | 例子效果 |
logical | 逻辑型:TRUE , FALSE | v<-TRUE; print(class(v)) | "logical" |
numeric | 数字型:23.4, 2 , | v<-23.5;print(class(v)) | "numeric" |
integer | 整型:2L, 0L | v<-2L;print(class(v)) | "numeric" |
complex | 复合型 | v<-3+2i;print(class(v)) | "complex" |
character | 字符型:'a',"FALSE" | v<-"TRUE";print(class(v)) | "character" |
raw | 原型:"Hello" 被存储为 48 65 6c 6c 6f | v<-charToRaw("Hello"); print(class(v)); print(v) |
[1] "raw" |
vectors | apple<-c("red","green"); print(apple); print(class(apple)) |
[1] "red" "green" |
|
list | 列表型 | list1<-list(c(2,5,3),21.3,sin);print(list1); print(class(list1)) |
[[1]] [[2]] [[3]] ################ [1] "list" |
Matrices | 矩阵型 | M=matrix(c('a','a','b'),nrow=2,ncol=3,byrow=TRUE); print(M) |
[,1] [,2] [,3] |
array | 数组型 |
#包含两个元素的数组,每个元素为2x3个矩阵 a <- array(c('green','yellow','e'),dim = c(2,3,2)); |
, , 1 [,1] [,2] [,3] , , 2 [,1] [,2] [,3] |
factor |
因子: 它将向量与向量中元素的不同值一起存储为标签。 标签总是字符, 不管它在输入向量中是数字还是字符或布尔等。 |
apple_colors<-c('green','green','yellow','red'); |
[1] green green yellow red |
data.frame | 数据帧:表格数据对象 |
BMI <- data.frame( |
gender height weight Age |