Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法以任意方式订购列表?例如,使用向量对列表进行排序:
> 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"
你的意思是重新订购吗?
##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"