regex - R regular expression replace :75% -> 0.75 -
surely naive question i'm in r , have expression
v <- "gastrula:75%"
that want replace "gastrula0.75"
i tried things :
v <- sub("\\.(\\d+)%","0.\\1",v) v <- sub("[:punct:](\\d)\\1+[:punct:]","0.\\1",v)
but didn't find worked.
here's possibility:
v <- "gastrula:75%" str <- unlist(strsplit(v,":")) paste0(str[1], as.numeric(gsub("%","",str[2]))/100)
Comments
Post a Comment