Skip to content
Prev 30965 / 398506 Next

How do I get 10^4 to become 10000?

Connolly
For an individual value you can use:
[1] 1e+05


However, that simple approach does not work with a vector, since the
'text' argument is treated as if it were single lines in an input
file.  Thus you need to do something like this to loop through the
vector elements:

# create the character vector
cv <- c("10 ^ 5", "10 ^ 4", "10 ^ 8")

# function to convert char vector elements to numeric
convtext <- function(x) eval(parse(text = x))

# use sapply to convert the vector
sapply(cv, convtext, USE.NAMES = FALSE)
[1] 1e+05 1e+04 1e+08


HTH,

Marc Schwartz