r - Extract integer value from a character string -
i have character in form "radiance_mult_band_1 = 1.2412e-02"
saved in variable. want extract integer value 0.012412
. please suggest syntax in r.
# function extract number string f = function(x) { y = unlist(strsplit(x, " ")) y = as.numeric(y) y = y[!is.na(y)] y } # having 1 value x = "radiance_mult_band_1 = 1.2412e-02" f(x) # [1] 0.012412 # having multiple values dt = data.frame(x = c("radiance_mult_band_1 = 1.2412e-02", "radiance_mult_band_2 = 1.5412e-02", "radiance_mult_band_3 = 2.2412e-02"), stringsasfactors = f) dt$value = f(dt$x) dt # x value # 1 radiance_mult_band_1 = 1.2412e-02 0.012412 # 2 radiance_mult_band_2 = 1.5412e-02 0.015412 # 3 radiance_mult_band_3 = 2.2412e-02 0.022412
Comments
Post a Comment