Learn R Programming

fritools (version 4.6.0)

powers_of_ten: Conversions from or to powers of ten.

Description

I often need to table big numbers in non-scientific notation.

Usage

convert_to_power_of_ten(x, exponent = NULL)

convert_from_power_of_ten(x)

df_to_powers_of_ten(x, is_individual = FALSE)

df_from_powers_of_ten(x)

Value

An attributed numeric vector.

A numeric vector.

A data frame with attributed numeric columns.

A data frame.

Arguments

x

A data frame with attributed numeric columns.

exponent

Specify an exponent instead of deriving one from the data.

is_individual

Use individual powers of ten for each numeric column in x? But why would you want to?

See Also

Other statistics: column_sums(), count_groups(), relative_difference(), round_half_away_from_zero(), sloboda(), weighted_variance()

Other vector functions: char2factor(), escape_non_ascii(), file_string()

Other vector functions: char2factor(), escape_non_ascii(), file_string()

Other statistics: column_sums(), count_groups(), relative_difference(), round_half_away_from_zero(), sloboda(), weighted_variance()

Other statistics: column_sums(), count_groups(), relative_difference(), round_half_away_from_zero(), sloboda(), weighted_variance()

Examples

Run this code
# Using vectors

print(x <- (5 + rnorm(15)) * 10^11)
convert_to_power_of_ten(x, 6)
print(y <- convert_to_power_of_ten(x))
all.equal(x, convert_from_power_of_ten(y))

# Using data frames 
## same exponent for all numeric columns
x <- (5 + rnorm(15)) * 10^11
df <- data.frame(x, y = x * 10^3, z = letters[seq_along(x)],
                row.names = as.character(seq_along(x)))
x <- df_to_powers_of_ten(df)
str(x)
y <- df_from_powers_of_ten(x) 
identical(df, y)
## individual exponents for different columns - but what for?
### automatically
### manually
df1 <- df
df1[["x"]] <- convert_to_power_of_ten(df1[["x"]])
df1[["y"]] <- convert_to_power_of_ten(df1[["y"]])
str(df1)
print(df2 <- df_from_powers_of_ten(df1))
identical(df, df2)

Run the code above in your browser using DataLab