Bootstrap : sample with replacement
——cf. R cookbook
R向量转变为类似于python字典的方法:names()
die <- 1:6
names(die)<-c("one" , "two" , "three" ,"four", "five" , "six")
# >die
##one two three four five six
##1 2 3 4 5 6
注:取消方法 names(die)<-NULL
R向量转变为matrix的方法:dim()/matrix ()
die <- 1:6
dim(die)<-c(2, 3)
# >die
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
继续变为data.frame方法: as.data.frame(die)
注:取消方法 dim(die)<-NULL
m<- matrix(die, nrow=2) 默认bycolumn将6个数字排列成两行
汇总:一个向量变成一个matrix的三种方法
hand1 <- c("ace", "king", "queen", "jack", "ten", "spades", "spades", "spades", "spades", "spades")
matrix(hand1, nrow = 5)
matrix(hand1, ncol = 2)
dim(hand1) <- c(5, 2)
hand2 <- c("ace", "spades", "king", "spades", "queen", "spades", "jack", "spades", "ten", "spades")
matrix(hand2, nrow = 5, byrow = TRUE)
matrix(hand2, ncol = 2, byrow = TRUE)
CLASS
changing the dimensions of your object (VECTOR) will not change the type of the object (double), but it will change the object's class (matrix)
综上
str 整体结构
typeof 数据类型
names 维度一 name
dim 维度二 dim
class 维度三 class