list.group: Divide list/vector elements into exclusive groups

Description Usage Arguments Value See Also Examples

View source: R/list.group.R

Description

Divide list/vector elements into exclusive groups

Usage

1
list.group(.data, ..., sorted = TRUE)

Arguments

.data

A list or vector

...

One or more expressions in the scope of each element to evaluate as keys

sorted

TRUE to sort the group keys. Ignored when the key has multiple entries.

Value

A list of group elements each contain all the elements in .data belonging to the group

See Also

list.ungroup

Examples

1
2
3
4
5
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.group(x, type)
list.group(x, mean(unlist(score)))

Example output

$A
$A$p1
$A$p1$type
[1] "A"

$A$p1$score
$A$p1$score$c1
[1] 10

$A$p1$score$c2
[1] 8




$B
$B$p2
$B$p2$type
[1] "B"

$B$p2$score
$B$p2$score$c1
[1] 9

$B$p2$score$c2
[1] 9



$B$p3
$B$p3$type
[1] "B"

$B$p3$score
$B$p3$score$c1
[1] 9

$B$p3$score$c2
[1] 7




$`8`
$`8`$p3
$`8`$p3$type
[1] "B"

$`8`$p3$score
$`8`$p3$score$c1
[1] 9

$`8`$p3$score$c2
[1] 7




$`9`
$`9`$p1
$`9`$p1$type
[1] "A"

$`9`$p1$score
$`9`$p1$score$c1
[1] 10

$`9`$p1$score$c2
[1] 8



$`9`$p2
$`9`$p2$type
[1] "B"

$`9`$p2$score
$`9`$p2$score$c1
[1] 9

$`9`$p2$score$c2
[1] 9

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