String Manipulation with stringr in R
Charlotte Wickham
Assistant Professor at Oregon State University
estimate <- 1.34019029100
$1.34
as.character(estimate)
"1.340190291"
format(estimate, digits = 3)
"1.34"
formatC(estimate,
format = "f", digits = 2)
"1.34"
Fixed: decimal point between ones and tenths
Scientific: decimal point after first digit
Fixed: decimal point between ones and tenths
Scientific: decimal point after first digit
Fixed: decimal point between ones and tenths
Scientific: decimal point after first digit
Fixed: decimal point between ones and tenths
Scientific: decimal point after first digit
1989000000000000000000000000000
1.989e+30
0.000000000008
8e-12
x <- c(1989000000000000000000000000000, 0.000000000008)
format(x, scientific = TRUE)
"1.989e+30" "8.000e-12"
format(x, scientific = FALSE)
"1988999999999999901909255192576.000000000000"
" 0.000000000008"
formatC(x, format = "f")
"1988999999999999901909255192576.0000"
"0.0000"
formatC(x, format = "e")
"1.9890e+30" "8.0000e-12"
formatC(x, format = "g")
"1.989e+30" "8e-12"
String Manipulation with stringr in R