Here are a few steps that will do what you want to do. This is not to say that this is the most effective or elegant solution ...
string <- "[(1.33738072607023, 27.9489435205271)]" string <- gsub("[^[:digit:]\\. \\s]", "", string) splt <- strsplit(string, " ")[[1]] names(splt) <- c("x","y") FOO <- function(name, strings) { assign(name, as.numeric(strings[name]), globalenv()) invisible() } lapply(c("x","y"), FOO, strings = splt)
The last line will return:
> lapply(c("x","y"), FOO, strings = splt) [[1]] NULL [[2]] NULL
And we have x and y assigned in the global environment
> x [1] 1.337381 > y [1] 27.94894
source share