Reputation: 35
I have a set of Latitudes stored in VARCHAR format in mysql database-
"[26.455359183496455,26.44229519242908,26.437069181137474,26.45489812668682]"
I have imported them in R and I want to work with them by converting them as float. I know that as.numeric()
is used for conversion but how to apply it in my case.
someone please guide me.
Upvotes: 3
Views: 47485
Reputation: 206496
You can do this in three steps.
gsub()
, strsplit()
, as.numeric()
). For exampleIn code this looks like
input <- "[26.455359183496455,26.44229519242908,26.437069181137474,26.45489812668682]"
as.numeric(strsplit(gsub("(^\\[|\\]$)", "", input), ",")[[1]])
Upvotes: 6