Constructors and methods for a proportion data type.
v_proportion
and prop
are synonyms that each create a
new v_proportion
object subclassed from v_continuous
and
vctrs_vctr
.
Support: \(\mathbf{[0, 1]}\)* (plus NA_real_
)
Prototype: double
* - i.e. floating-point number
v_proportion(
x = ptypeFUN(),
internal_name = "",
context,
auto_compute_summary = auto_compute_default,
extra_descriptors = list()
)
prop(
x = ptypeFUN(),
internal_name = "",
context,
auto_compute_summary = auto_compute_default,
extra_descriptors = list()
)
is_proportion(x)
is_prop(x)
as_proportion(x)
# S3 method for v_proportion
as_canonical(x)
nonnegative double
the internal name of the variable
a context
an indicator of whether the data_summary
is
automatically computed whenever a vector is initialized, subset, or
concatenated. Defaults to TRUE
. If this option is set to FALSE
,
then get_data_summary
is the only way to compute the summary.
The data_summary_l
lens will return an empty data_summary
.
A list
of descriptors
functions
appended to the default descriptors
.
Other stype types:
tbl_analysis
,
v_binary
,
v_continuous_nonneg
,
v_continuous
,
v_count
,
v_nominal
,
v_ordered
,
v_rcensored
# Example data
src_dbl <- c(1, 0.5, .01, 0, NA_real_)
# Constructor for the `v_proportion` class. One can also use `prop`
# which is a synonym for the `v_proportion` function.
v <- v_proportion(
x = src_dbl,
internal_name = "v_example",
context = context(
short_label = "important_var",
long_label = "Very important variable"
),
extra_descriptors = list()
)
# Helper functions and methods
is_proportion(v)
#> [1] TRUE
as_proportion(src_dbl)
#> <proportion[5]>
#> [1] 1 0.5 0.01 0 <NA>
#> Mean = 0.378; SD = 0.476; Missing = 1
as.character(v)
#> [1] "1" "0.5" "0.01" "0" NA
as_canonical(v)
#> [1] 1.00 0.50 0.01 0.00 NA