1

有没有办法以任意方式订购列表?例如,使用向量对列表进行排序:

> a
[[1]]
[1] 1

[[2]]
[1] "B"

[[3]]
[1] 2

> b = c(3, 1, 2)
> magicfunction(a, b)
[[1]]
[1] 2

[[2]]
[1] 1

[[3]]
[1] "B"
4

1 回答 1

5

你的意思是重新订购吗?

##Create some dummy data
R> a = list(3)
R> a[[1]] = 1; a[[2]] = "B"; a[[3]] = 2
R> b = c(3, 1, 2)

然后只需使用数字向量进行排序:

R> a[b]
[[1]]
[1] 2

[[2]]
[1] 1

[[3]]
[1] "B"
于 2013-02-06T09:41:29.227 回答