创建列表
让我们来创建第一个列表!要构造列表,请使用函数 list():
my_list <- list(comp1, comp2 ...)
传给 list 函数的参数就是列表的各个组件。请记住,这些组件可以是矩阵、向量、其他列表等。
本练习是课程的一部分
R 入门
练习说明
构建一个名为 my_list 的列表,其中包含变量 my_vector、my_matrix 和 my_df 作为列表组件。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Vector with numerics from 1 up to 10
my_vector <- 1:10
# Matrix with numerics from 1 up to 9
my_matrix <- matrix(1:9, ncol = 3)
# First 10 elements of the built-in data frame mtcars
my_df <- mtcars[1:10,]
# Construct list with these different elements:
my_list <-