Re: [R] Extract character strings from a vector

2016-06-21 Thread David Winsemius
> On Jun 21, 2016, at 3:09 PM, William Dunlap via R-help > wrote: > > You could remove all non-digits from the strings with >> gsub("[^[:digit:]]+", "", x) > [1] "0122" "" "" "89963" "1" "8" > and then count the number of characters remaining with nchar >> x[nchar(gsub("[^[:dig

Re: [R] Extract character strings from a vector

2016-06-21 Thread William Dunlap via R-help
You could remove all non-digits from the strings with > gsub("[^[:digit:]]+", "", x) [1] "0122" "" "" "89963" "1" "8" and then count the number of characters remaining with nchar > x[nchar(gsub("[^[:digit:]]+", "", x)) <= 1] [1] "RTG" "GF TYHH" "KFTR1" "RT 8" Or you

[R] Extract character strings from a vector

2016-06-21 Thread Marine Regis
Hello, I have a vector x of character strings: x <- c("LM0122","RTG", "GF TYHH", "HJN 89963", "KFTR1","RT 8") >From this vector, how can I extract the following character strings (i.e., >which contain 0 or 1 numeric value) [1] "RTG" "GF TYHH" "KFTR1" "RT 8" Thank you v