[1] 0 0 0 0 0> vector("complex",6)[1] 0+0i 0+0i 0+0i 0+0i 0+0i 0+0i> vector("logical",6)[1] FALSE FALSE FALSE FALSE FALSE FALSE> vector("character",4)[1] "" "" "" ""> vector("list",5)[[1]]NULL[[2]]NULL[[3]]NULL[[4]]NULL[[5]]NULL
> seq.int(5,8) #相当于 5:8[1] 5 6 7 8> seq.int(3,12,2) #可指定步长为2[1] 3 5 7 9 11
> str <- c("Peter","Kate","Jim")> length(str)[1] 3> nchar(str)[1] 5 4 3
> x <- (1:5)^2> x[c(1,3,5)][1] 1 9 25> x[c(-2,-4)][1] 1 9 25> x[c(TRUE,FALSE,TRUE,FALSE,TRUE)][1] 1 9 25
> (three_d_array <- array(1:24,dim = c(4,3,2),dimnames = list(c("one","two","three","four"),c("five","six","seven"),c("eight","nine")))), , eightfive six sevenone 1 5 9two 2 6 10three 3 7 11four 4 8 12, , ninefive six sevenone 13 17 21two 14 18 22three 15 19 23four 16 20 24
> (a_matrix <- matrix(1:12,nrow = 4,dimnames = list(c("one","two","three","four"),c("one","two","three"))))one two threeone 1 5 9two 2 6 10three 3 7 11four 4 8 12
> (a_matrix <- matrix(1:12,nrow = 4,byrow = TRUE,dimnames = list(c("one","two","three","four"),c("one","two","three"))))one two threeone 1 2 3two 4 5 6three 7 8 9four 10 11 12
> a_matrix[1,c("two","three")]two three2 3> a_matrix[1, ]one two three1 2 3> a_matrix[ ,c("one","three")]one threeone 1 3two 4 6three 7 9four 10 12
> (another_matrix <- matrix(seq.int(2,24,2),nrow = 4,dimnames = list(c("one","two","three","four"),c("one","two","three"))))one two threeone 2 10 18two 4 12 20three 6 14 22four 8 16 24> c(a_matrix,another_matrix)[1] 1 4 7 10 2 5 8 11 3 6 9 12 2 4 6 8 10 12 14 16 18 20 22 24
> cbind(a_matrix, another_matrix)one two three one two threeone 1 2 3 2 10 18two 4 5 6 4 12 20three 7 8 9 6 14 22four 10 11 12 8 16 24> rbind(a_matrix, another_matrix)one two threeone 1 2 3two 4 5 6three 7 8 9four 10 11 12one 2 10 18two 4 12 20three 6 14 22four 8 16 24
> a_matrix %*% t(a_matrix)one two three fourone 14 32 50 68two 32 77 122 167three 50 122 194 266four 68 167 266 365
> 1:3 %o% 4:6[,1] [,2] [,3][1,] 4 5 6[2,] 8 10 12[3,] 12 15 18
原文地址:http://blog.csdn.net/luoyhang003/article/details/38338565