0
点赞
收藏
分享

微信扫一扫

R语言创建列表

史值拥 2022-05-09 阅读 39


创建四个成份的列表:字符串、数值型向量、矩阵以及字符型向量。组合可以任意,最后保存为列表。

> g <- "My First List"

> h <- c(25,26,18,39)

> j <- matrix(1:10, nrow = 5)

> k <- c("one","two","three")

> mylist <- list(title=g,ages=h,j,k)

> mylist
$title
[1] "My First List"

$ages
[1] 25 26 18 39

[[3]]
[,1] [,2]
[1,] 1 6
[2,] 2 7
[3,] 3 8
[4,] 4 9
[5,] 5 10

[[4]]
[1] "one" "two" "three"


> mylist[[2]]
[1] 25 26 18 39



举报

相关推荐

0 条评论