exception with gsub in R -
i trying replace strings "other", except ones starting numbers in following example:
strings <- c("test.5","5.test","6.test","test","test") i found code below replaces strings starting numbers:
gsub("^[0-9].+", "other", strings) "test.5" "other" "other" "test" "test" however, confused how reverse statement, except these strings replaced.
desired answer be
"other" "5.test" "6.test" "other" "other" can me out? in advance!
try
sub('^[^0-9].*', "other", strings) #[1] "other" "5.test" "6.test" "other" "other"
Comments
Post a Comment