list.order: Give the order of each list element by expression

Description Usage Arguments Value See Also Examples

View source: R/list.order.R

Description

Give the order of each list element by expression

Usage

1
list.order(.data, ..., keep.names = FALSE, na.last = TRUE)

Arguments

.data

A list or vector

...

A group of lambda expressions

keep.names

Whether to keep the names of x in the result

na.last

The way to deal with NAs.

Value

an integer vector.

See Also

list.sort

Examples

1
2
3
4
5
6
x <- list(p1 = list(type='A',score=list(c1=10,c2=8)),
       p2 = list(type='B',score=list(c1=9,c2=9)),
       p3 = list(type='B',score=list(c1=9,c2=7)))
list.order(x, type, (score$c2)) # order by type (ascending) and score$c2 (descending)
list.order(x, min(score$c1,score$c2))
list.order(x, min(score$c1,score$c2), keep.names=TRUE)

Example output

[1] 1 2 3
[1] 3 1 2
p1 p2 p3 
 3  1  2 

rlist documentation built on Sept. 5, 2021, 5:30 p.m.