[R] find and replace

arun smartpink111 at yahoo.com
Tue Aug 28 15:37:32 CEST 2012



Hi,
Try this:
dat1<-readLines(textConnection(
 "ID Name Fav_Place
 101 Andrew  Phoenix,AZ
 201 John SanFrancisco
 303 Julie California/New York
 304 Monica  New York"))
 gsub("Phoenix","Tucson",gsub("New York","New York City",dat1))
#[1] "ID Name Fav_Place"                  "101 Andrew  Tucson,AZ"             
#[3] "201 John SanFrancisco"              "303 Julie California/New York City"
#[5] "304 Monica  New York City" 
A.K.

----- Original Message -----
From: Sapana Lohani <lohani.sapana at ymail.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Monday, August 27, 2012 7:47 PM
Subject: [R] find and replace

Hi, 

My data frame (Students) is

ID Name Fav_Place
101 Andrew  Phoenix AZ
201 John San Francisco
303 JulieCalifornia / New York
304 Monica  New York

How can I replace Phoenix with Tucson & New York with New York City in the df?

Thanks
    [[alternative HTML version deleted]]


______________________________________________
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.





More information about the R-help mailing list