有没有办法以任意方式订购列表?例如,使用向量对列表进行排序:
> 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"
答案 0 :(得分: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"