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