Message-ID: <CAAxdm-55JTi=ydP0Q+tLo+58TkseH0abkp3Jx98wHnYf4vL56Q@mail.gmail.com>
Date: 2012-08-28T02:54:57Z
From: jim holtman
Subject: find and replace
In-Reply-To: <1346098792.55894.YahooMailNeo@web125203.mail.ne1.yahoo.com>
I am making the assumption that all the columns are character and not factors:
for (i in c("A", "B", "C", "D", "E")){
yourdf[[i]] <- ifelse(yourdf[[i]] == 'x'
, 'y'
, ifelse(yourdf[[i]] == 'a'
, 'b'
, yourdf[[i]]
)
)
}
On Mon, Aug 27, 2012 at 4:19 PM, Sapana Lohani <lohani.sapana at ymail.com> wrote:
> I have 5 (A,B,C,D,E) columns in my dataframe. I want to replace all "x" with "y" and all "a" with "b" within these 5 columns. Can I do it in one step?
>
> 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.
--
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.