【发布时间】:2019-04-15 08:47:55
【问题描述】:
我使用 R 中的向量创建了一个列表列表(比如说parentList)。parentList 由 100 个列表 childList1、childList2 等组成。每个这样的childList 都包含一个元素列表(grandChildVariable1、grandChildVariable2 等等)。除parentList 外,所有列表和变量均未命名。
我想根据每个 childList 的第二个元素 (grandChildVariable2) 对 parentList 进行排序。我可以使用parentList[[2]][2] 获取此变量的值。但我不太确定如何对整个列表进行排序。
我目前正在尝试按如下方式对其进行排序:
sorted_list <- parentList[order(sapply(parentList,'[[',2))] 但它只拾取第二个列表元素 childList2 并返回以下错误:unimplemented type 'list' in 'orderVector1'。
【问题讨论】: