array_df_ratetable_utils {popEpi} | R Documentation |
array
s, data.frame
s and ratetable
s
Description
Utilities to transform objects between array
, data.frame
, and
survival::ratetable.
Usage
long_df_to_array(x, stratum.col.nms, value.col.nm)
long_df_to_ratetable(
x,
stratum.col.nms,
value.col.nm,
dim.types,
cut.points = NULL
)
long_dt_to_array(x, stratum.col.nms, value.col.nm)
long_dt_to_ratetable(
x,
stratum.col.nms,
value.col.nm,
dim.types,
cut.points = NULL
)
array_to_long_df(x)
array_to_long_dt(x)
array_to_ratetable(x, dim.types, cut.points = NULL)
ratetable_to_array(x)
ratetable_to_long_df(x)
ratetable_to_long_dt(x)
Arguments
x |
|
stratum.col.nms |
a vector of column names in |
value.col.nm |
name of column in |
dim.types |
see |
cut.points |
see
|
Details
-
long_df_to_array
: converts a long-formatdata.frame
to anarray
with one or more dimensions
-
long_df_to_ratetable
: callslong_df_to_array
and thenarray_to_ratetable
-
long_dt_to_array
: simply asserts thatx
is adata.table
and callslong_df_to_array
-
long_dt_to_ratetable
: callslong_dt_to_array
and thenarray_to_ratetable
-
array_to_long_df
: converts an array with one or more dimensions into a long-formatdata.frame
; any dimnames are used to name and fill the stratifying columns; for dimensions without a name,".dX"
is used for stratifying column numberX
; for eachk
, if there are no contents indimnames(x)[[k]]
, the elements ofseq(dim(x)[k])
are used to fill the corresponding stratifying column; the value column always has the name"value"
-
array_to_long_dt
: callsarray_to_long_df
and converts result to adata.table
for convenience
-
array_to_ratetable
: converts an array to a survival::ratetable
-
ratetable_to_array
: converts a survival::ratetable to an array
-
ratetable_to_long_df
: callsratetable_to_array
and thenarray_to_long_df
-
ratetable_to_long_dt
: callsratetable_to_array
and thenarray_to_long_dt
Value
-
long_df_to_array
: anarray
-
long_df_to_ratetable
: a survival::ratetable -
long_dt_to_array
: anarray
-
long_dt_to_ratetable
: a survival::ratetable -
array_to_long_df
: andata.frame
-
array_to_long_dt
: andata.table
-
array_to_ratetable
: a survival::ratetable -
ratetable_to_array
: anarray
-
ratetable_to_long_df
: adata.frame
-
ratetable_to_long_dt
: adata.table
Examples
long_dt <- popEpi::popmort
arr <- long_df_to_array(long_dt, c("agegroup", "year", "sex"), "haz")
rt <- array_to_ratetable(arr, dim.types = c(2L, 4L, 1L))
arr2 <- ratetable_to_array(rt)
long_df2 <- array_to_long_df(arr2)
identical(sort(long_dt[["haz"]]), sort(long_df2[["value"]]))