1. 当函数有多个返回值的时候,打包成一个list
2. 对矩阵的行列进行命名的时候
matrix(1:9, nrow = 3, byrow = TRUE,
dimnames = list(c("r1","r2","r3"), c("c1","c2","c3")))
3. as.list
as.list() # 将向量转换成列表:
l2 = as.list(c(a = 1, b = 2))
l2
#> $a
#> [1] 1
#>
#> $b
#> [1] 2
4.对满足条件的列做多种汇总
df_grp = df %>%
group_by(class) %>%
summarise(across(where(is.numeric),list(sum=sum, mean=mean, min=min), na.rm = TRUE))
~~ df ~~