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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -