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.
次のリストがあります。
myList <- list(list(a = 1,b = 1:5,x = 2), list(a = 7,b = 9.1,x = 3), list(a=-1, b = 0.2, x = 1))
そして、このリストの要素を基準「x」で並べ替えたいと思います。私はそれを行う方法に途方に暮れています。どんな助けでも大歓迎です。
myList[order(sapply(myList, "[[", "x"))]
トリックを行います
[[1]] [[1]]$a [1] -1 [[1]]$b [1] 0.2 [[1]]$x [1] 1 [[2]] [[2]]$a [1] 1 [[2]]$b [1] 1 2 3 4 5 [[2]]$x [1] 2 [[3]] [[3]]$a [1] 7 [[3]]$b [1] 9.1 [[3]]$x [1] 3