GRTSmaster_habitats
data source to
base 4 fractionsR/GRTSmh.R
convert_dec_to_base4frac.Rd
Converts decimal (i.e. base 10) integer values from the raster data source
GRTSmaster_habitats
into base 4 fractions, using a precision of
13 digits behind the decimal mark (as needed to cope with the range of
values).
For example, the integer 16
(= 4^2
) is converted into
0.0000000000100
and 4^12
is converted into
0.1000000000000
.
convert_dec_to_base4frac(x)
x | A decimal (i.e. base 10) scalar or vector of integer values from the
|
---|
The corresponding base4 scalar or vector, stored as a fraction.
Long base 4 fractions seem to be handled and stored easier than long (base 4) integers. This approach follows the one of Stevens & Olsen (2004) to represent the reverse hierarchical order in a GRTS sample as base-4-fraction addresses.
The function works on a vector and retains NA
values.
As such, it can be used in raster::calc()
.
When writing such a raster to a file, it is needed to use the FLT8S
data type (see dataType
).
Otherwise several digits will change.
The function is based on code from the baseConvert()
function
in Will Gray's Gmisc package.
Stevens D.L. & Olsen A.R. (2004). Spatially Balanced Sampling of Natural Resources. Journal of the American Statistical Association 99 (465): 262–278. doi:10.1198/016214504000000250 .
Other functions involved in processing the 'GRTSmaster_habitats' data source:
convert_base4frac_to_dec()
,
read_GRTSmh()
,
read_GRTSmh_base4frac()
,
read_GRTSmh_diffres()
oldoption <- options(list(digits = 15, scipen = 999)) convert_dec_to_base4frac(c(14, 15, NA, 456)) #> [1] 0.0000000000032 0.0000000000033 NA 0.0000000013020 options(oldoption)