I have dataset, which negative value is presented with a bracket around the number i.e. (10)==-10, it is in csv format, how can I process it so that R will inte
If you know the surrounding parentheses will be the only ones in the unit, you can create a function to deal with them:
test <- c(10, "(10)", 5)
negative_paren <- function(vec){
#the backspace escapes the special "(" character
vec <- gsub("\\(","-",vec)
vec <- gsub("\\)","",vec)
vec <- as.numeric(vec)
return(vec)
}
negative_paren(test)
[1] 10 -10 5