list.unzip: Transform a list of elements with similar structure into a...

Description Usage Arguments See Also Examples

View source: R/list.zip.R

Description

Transform a list of elements with similar structure into a list of decoupled fields

Usage

1
2
3
4
5
6
7
list.unzip(
  .data,
  .fields = c("intersect", "union"),
  ...,
  .aggregate = "simplify2array",
  .missing = NA
)

Arguments

.data

A list of elements containing common fields

.fields

'intersect' to select only common fields for all .data's elements. 'union' to select any field that is defined in any elements in .data.

...

The custom aggregate functions. Can be a named list of functions or character vectors. If a function is specified as a list of functions, then the functions will be evaluated recursively on the result of the field. Use identity to avoid aggregating results. Use NULL to remove certain field.

.aggregate

The default aggregate function, by default, simplify2array. Can be a function, character vector or a list of functions. Use identity to avoid aggregating results.

.missing

When .fields is 'union' and some elements do not contain certain fields, then NULL will be replaced by the value of .missing, by default, NA. This often makes the result more friendly.

See Also

list.zip

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
list.unzip(list(p1 = list(a = 1, b = 2), p2 = list(a = 2, b = 3)))
list.unzip(list(p1 = list(a = 1, b = 2), p2 = list(a = 2, b = 3, c = 4)))
list.unzip(list(p1 = list(a = 1, b = 2), p2 = list(a = 2, b = 3, c = 4)), 'union')
list.unzip(list(p1 = list(a = 1, b = 2), p2 = list(a = 2, b = 3, c = 4)), 'union', a = 'identity')
list.unzip(list(p1 = list(a = 1, b = 2), p2 = list(a = 2, b = 3, c = 4)), 'intersect', a = NULL)

x <-
 list(april = list(n_days = 30,
   holidays = list(list('2015-04-01', 'april fools'),
 list('2015-04-05', 'easter')),
   month_info = c(number = '4', season = 'spring')),
     july = list(n_days = 31,
 holidays = list(list('2014-07-04', 'july 4th')),
   month_info = c(number = '7', season = 'summer')))
list.unzip(x, holidays = c('list.ungroup', 'unname', 'list.stack',
  function(df) setNames(df, c("date", "name"))))

Example output

$a
p1 p2 
 1  2 

$b
p1 p2 
 2  3 

$a
p1 p2 
 1  2 

$b
p1 p2 
 2  3 

$a
p1 p2 
 1  2 

$b
p1 p2 
 2  3 

$c
p1 p2 
NA  4 

$a
$a$p1
[1] 1

$a$p2
[1] 2


$b
p1 p2 
 2  3 

$c
p1 p2 
NA  4 

$b
p1 p2 
 2  3 

$n_days
april  july 
   30    31 

$holidays
        date        name
1 2015-04-01 april fools
2 2015-04-05      easter
3 2014-07-04    july 4th

$month_info
       april    july    
number "4"      "7"     
season "spring" "summer"

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