我想根据条件在列表中排列项目,就像dplyr :: arrange在data.frames中所做的(同时保持链接的语法)。
## Something along the lines of:
list(
list( foo="baz" ),
list( foo="test" ),
list( foo="bar" )
) %>% arrange( foo )
## .. would result in a structure equivalent of:
list(
list( foo="bar" ),
list( foo="baz" ),
list( foo="test" )
)
我希望存在类似的东西,但找不到它
编辑:为了清楚起见,我删除了变量“ l”
EDIT2:不能使用dplyr :: arrange更改路径,因为元素可能不支持它,或者它们可能没有匹配的名称
您可以unlist
,sort
,并使用relist
将其放回相同的结构。
relist(sort(unlist(l)), l)
#[[1]]
#[[1]]$foo
#[1] "bar"
#[[2]]
#[[2]]$foo
#[1] "baz"
#[[3]]
#[[3]]$foo
#[1] "test"