RON70 wrote: > Thanks for these suggestions. However I have one more question. Is there any > way to extract only numbers? For example I want to extract only "88" in my > example. >
if you have just one integer number represented in a single string, here's one way go: strings = c('foo 1', '2 bar', 'and 3 as well') (numbers = gsub('.*([0-9]+).*', '\\1', strings)) you will need to modify the regex if other sorts of numbers are encoded. if more than one number is to be extracted from a single string, you can try the package gsubfn: strings = c('foo 1', '2 bar', 'and 3 and 4, too') strapply(strings, '[0-9]+') vQ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.