|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Compare columnsDear R-users,
I have the following 2 files; A V1 V2 A 1 A 2 A 3 A 4 B 1 B 4 C 1 C 3 D 4 B V1 V2 process1 1 process2 2 process3 3 process4 4 I want to get this output C V1 V2 V3 A 1 process1 A 2 process2 A 3 process3 A 4 process4 B 1 process1 B 4 process4 C 1 process1 C 3 process3 D 4 process4 I want to compare A$V2 with B$V2, if it is the same, then append B$V1 to A. Any tips are highly appreciated. TQVM! -- Suhaila Zainudin PhD Candidate Universiti Teknologi Malaysia [[alternative HTML version deleted]] ______________________________________________ R-help@... 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. |
|
|
Re: Compare columnsHi Suhaila,
Is this what you want? A=" V1 V2 A 1 A 2 A 3 A 4 B 1 B 4 C 1 C 3 D 4" B="V1 V2 process1 1 process2 2 process3 3 process4 4" A=read.table(textConnection(A),header=TRUE) B=read.table(textConnection(B),header=TRUE) A$V3<-ifelse(A$V2%in%B$V2,paste('process',A$V2,sep="")) A V1 V2 V3 A 1 process1 A 2 process2 A 3 process3 A 4 process4 B 1 process1 B 4 process4 C 1 process1 C 3 process3 D 4 process4 HTH, Jorge On Tue, May 13, 2008 at 3:08 AM, Suhaila Zainudin < suhaila.zainudin@...> wrote: > Dear R-users, > > I have the following 2 files; > > A > > V1 V2 > A 1 > A 2 > A 3 > A 4 > B 1 > B 4 > C 1 > C 3 > D 4 > > B > > V1 V2 > process1 1 > process2 2 > process3 3 > process4 4 > > I want to get this output > > C > V1 V2 V3 > A 1 process1 > A 2 process2 > A 3 process3 > A 4 process4 > B 1 process1 > B 4 process4 > C 1 process1 > C 3 process3 > D 4 process4 > > > I want to compare A$V2 with B$V2, if it is the same, then append B$V1 to > A. > > > Any tips are highly appreciated. TQVM! > > > > -- > Suhaila Zainudin > PhD Candidate > Universiti Teknologi Malaysia > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@... 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. > [[alternative HTML version deleted]] ______________________________________________ R-help@... 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. Thanks,
Jorge Ivan Velez |
| Free Forum Powered by Nabble | Forum Help |