1. 当函数有多个返回值的时候,打包成一个list

2. 对矩阵的行列进行命名的时候

  1. matrix(1:9, nrow = 3, byrow = TRUE,
  2. dimnames = list(c("r1","r2","r3"), c("c1","c2","c3")))

3. as.list

  1. as.list() # 将向量转换成列表:
  2. l2 = as.list(c(a = 1, b = 2))
  3. l2
  4. #> $a
  5. #> [1] 1
  6. #>
  7. #> $b
  8. #> [1] 2

4.对满足条件的列做多种汇总

  1. df_grp = df %>%
  2. group_by(class) %>%
  3. summarise(across(where(is.numeric),list(sum=sum, mean=mean, min=min), na.rm = TRUE))

~~ df ~~