[R] Replacing data values from ref table
arun
smartpink111 at yahoo.com
Thu Aug 22 04:34:37 CEST 2013
Hi,
You may try ?merge() or ?join() from library(plyr)
dat1<- read.table(text="
Col1 Col2
red 1.23
blu 4.56
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat2<- read.table(text="
Col1 Col2
red SQU
blu CIR
",sep="",header=TRUE,stringsAsFactors=FALSE)
library(plyr)
res1<-join(dat2,dat1,by="Col1")[,-1]
colnames(res1)<- colnames(dat1)
res1
# Col1 Col2
#1 SQU 1.23
#2 CIR 4.56
#or
res2<-merge(dat2,dat1,by="Col1")[,-1]
colnames(res2)<-colnames(dat1)
res2
# Col1 Col2
#1 CIR 4.56
#2 SQU 1.23
A.K.
Hi R wizards,
Thanks in advance for your patience.
I can't figure out how to replace values in one column with their
equivalent values that are stored in another table. Any ideas?
Data table
Col1 Col 2
red 1.23
blu 4.56
Reference table
Col1 Col2
red SQU
blu CIR
Desired Output
Col1 Col2
SQU 1.23
CIR 4.56
More information about the R-help
mailing list