Working with very small values in R
Published:
When you’re working on extremely small floating numbers in R (such as when you have strong p-values), there are a few options.
- Rmpfr package
- Parse the string of values in scientific notation. Let’s say you have small values in
P
column in a dataframedf
and those numbers are represented as1e-400
etc. Then, you can run something like this to parse and compute thelog10(P)
value.
df %>%
separate(
p_value, c("P_base", "P_exp"),
sep = "e", remove = F, fill = "right"
) %>%
replace_na(list(P_exp = "0")) %>%
mutate(log10P = log10(as.numeric(P_base)) + as.numeric(P_exp))