editor 发表于 2013-3-2 22:44:42

R语言中unlist是干嘛用的?—R-China小编问题(29)

童鞋A:R中unlist是干嘛用的?
童鞋B:
“Given a list structure x, unlist simplifies it to produce a vector which contains all the atomic components which occur in x.”
童鞋A:
ok i see.thx
还能不能用汉语解释一下,并给出个例子啥的,解释一下?

moshengren 发表于 2013-3-3 10:21:41

unlist()函数的作用,就是将list结构的数据,变成非list的数据,即将list数据变成字符串向量或者数字向量的形式。
例如
require(graphics)

# create a plotting structure
pts <- list(x=cars[,1], y=cars[,2])

ulist(pts)
大家可以再举例子说明

赵赵赵 发表于 2021-7-19 16:28:08

上面那位兄弟回答得挺好的了,补充个小例子吧:loveliness:

> list1 <- list(a=c(1,2,3),
+               b=c(5,7,8))
> unlist1 <- unlist(list1)
> unlist1
a1 a2 a3 b1 b2 b3
123578
> class(unlist1)
"numeric"
> unlist1+1
a1 a2 a3 b1 b2 b3
234689
> names(unlist1)
"a1" "a2" "a3" "b1" "b2" "b3"
> unlist1['a3']
a3
3
页: [1]
查看完整版本: R语言中unlist是干嘛用的?—R-China小编问题(29)