数组初始化

数组和集合 / 数组

# Empty vectors of a type
n1 <- numeric(0)
n2 <- character(0)

# One-dimensional vectors
n3 <- c(1, 2, 3)
n4 <- c("1", "2", "3")

# From a range
n5 <- 1:3

# Rows may differ in length: a list of vectors
n6 <- list(c(1, 2), c(3, 4, 5))

# Rectangular 2 x 3, filled with zeros
n7 <- matrix(0, nrow = 2, ncol = 3)

str(n1)
str(n2)
str(n3)
str(n4)
str(n5)
str(n6)
print(n7)