as.data.frame.LifeTable: Coerce a life table to a data frame.

Description Usage Arguments Details Value See Also Examples

View source: R/LifeTable-methods.R

Description

Convert a LifeTable object to a "long form" data frame. The life table functions that are included in the data frame are controlled by the showFun slot of the life table. If the life table has iterations, the use of quantiles to summarise these iterations is controlled by the showQuantiles and prob slots.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## S3 method for class 'LifeTable'
as.data.frame(
  x,
  row.names = NULL,
  optional = FALSE,
  stringsAsFactors = default.stringsAsFactors(),
  responseName = "value",
  ...
)

## S4 method for signature 'LifeTable'
as.data.frame(
  x,
  row.names = NULL,
  optional = FALSE,
  stringsAsFactors = default.stringsAsFactors(),
  responseName = "value",
  ...
)

Arguments

x

An LifeTable object.

row.names

See as.data.frame.

optional

See as.data.frame.

stringsAsFactors

See as.data.frame.

responseName

The name of the final column of the table. Defaults to "value"

...

Additional arguments to be passed to or from methods.

Details

as.data.frame is often called as a step towards exporting a life table as a .csv file.

as.data.frame prints the dimensions of the life table in reverse order, with the "age" dimension last. This ordering is different from the one used by base function as.data.frame.array, but, with life tables, is usually what is wanted.

Value

A data.frame.

See Also

Life tables are created by function LifeTable.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
mx <- dembase::ValuesOne(c(0.2, 0.05, 0.1, 0.4),
               labels = c("0", "1-4", "5-9", "10+"),
               name = "age")
lt <- LifeTable(mx)
lt
as.data.frame(lt)

showFun(lt) <- c("ex", "Tx")
as.data.frame(lt)


## life table with iterations
mx <- dembase::ValuesOne(c(0.2, 0.05, 0.1, 0.4),
               labels = c("0", "1-4", "5-9", "10+"),
               name = "age")
mx <- dembase::perturb(1000 * mx, n = 10) / 1000
lt <- LifeTable(mx)
lt
as.data.frame(lt)
showQuantiles(lt) <- FALSE
lt
as.data.frame(lt)
showQuantiles(lt) <- TRUE
prob(lt) <- c(0.1, 0.8)
lt
as.data.frame(lt)

StatisticsNZ/demlife documentation built on April 27, 2021, 10:02 p.m.