Skip to content
Prev 333540 / 398513 Next

Datatable manipulation

Hi,
Assuming that this is the case:
dat1 <- read.table(text="a???? b???? c???? d?????? e
1???? 2???? 3???? 4???? 5
10???? 9???? 8???? 7???? 6",sep="",header=TRUE)

Names1<- read.table(text="Original????? New?? 
e???? ee
g??? gg
a???? aa
c???? cc
f???? ff",sep="",header=TRUE,stringsAsFactors=FALSE)
?
?indx <- match(names(dat1),Names1[,1])
?names(dat1)[names(dat1) %in% Names1[,1]] <- Names1[,2][indx[!is.na(indx)]]
?dat1
#? aa b cc d ee
#1? 1 2? 3 4? 5
#2 10 9? 8 7? 6


A.K.
On Friday, November 22, 2013 4:46 AM, Nitisha jha <nitisha999 at gmail.com> wrote:
Hey! I got this one. :)
For the match function, actually I just want the ones that are matching to be replaced. Rest should stay the same. How do I do that? When I tried your command, if there is no match, it writes var2 or something.?
Message-ID: <1385128657.10818.YahooMailNeo@web142605.mail.bf1.yahoo.com>
In-Reply-To: <CAOdnBQeaoEJ1+oChvSz_OSPcNeeNdi1SavuZ=RXVHExb9tiXXA@mail.gmail.com>