I have a vector of numbers and characters that are treated as characters, for example:
mix <- c("50", ">10^4", "<10", "325")
I understand how to strip off the > and < and apply as.numeric(). However, this results in a NA value for "10^4".
I've tried to use eval("10^4") however this doesn't work and simply returns the character.
Currently, my function is:
f_convert2numeric <- function(vec){
nvec = eval(as.numeric(gsub(">","",gsub("<","",vec))))
return(nvec)
}
Is there any way to add in this ability to convert characters using ^ to numeric? Preferably in base R but happy with alternatives.