10  向量化

10.1 对应元素运算

x<-1:10
y<-10:1
x+y
 [1] 11 11 11 11 11 11 11 11 11 11

10.2 循环补足

x<-rep(100,time=10)
x + 1
 [1] 101 101 101 101 101 101 101 101 101 101
x + 1:2
 [1] 101 102 101 102 101 102 101 102 101 102
x + 1:3
Warning in x + 1:3: longer object length is not a multiple of shorter object
length
 [1] 101 102 103 101 102 103 101 102 103 101
x + 1:4
Warning in x + 1:4: longer object length is not a multiple of shorter object
length
 [1] 101 102 103 104 101 102 103 104 101 102
x + 1:5
 [1] 101 102 103 104 105 101 102 103 104 105
data<-data.frame(x=1:6)
data
data$y=c('A','B','C')
data
# data$z=1:5 报错,因为6不能被5整除