[R] Replacing a character string when finding substring match

From: Judith Flores <juryef_at_yahoo.com>
Date: Thu, 14 Feb 2008 10:57:22 -0800 (PST)


Dear R-experts,

  I need to replace the values of a vector(tx) with a word ('Vehicle') when the value of the vector contains the word 'vehicle'. Sometimes, the value could be 'MCT vehicle', or 'control-vehicle', etc.
  I tried gsub like this

treatment<-gsub('vehicle','Vehicle', tx, ignore.case=T)

   But then I end up with values like 'MCT Vehicle' or
'control-Vehicle'. I want the values to be one word:
'Vehicle'.
    

Thank you in advance for any help.



Be a better friend, newshound, and

R-help_at_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. Received on Thu 14 Feb 2008 - 19:00:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 14 Feb 2008 - 19:30:51 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive