[R] problem merging two data sets ( one with a header and one without)
kayj
kjaja27 at yahoo.com
Thu Aug 21 16:59:27 CEST 2008
I have two set of data, Data1 and Data2 . Data1 has a header and Data2 does
not. I would like to merge the two data sets after removing some columns
from data2 .
I am having a problem merging so I had to write and read final data and
specify the “header=F” so the merge can be done by”V1”. Is there a way to
avoid this step. The problem is when I do cbind the FinalData has different
column names
Data1<-read.table("data1.txt", sep='\t', header=F, stringsAsFactors=F)
Data2<-read.table("data2.txt", sep='\t', header=T, stringsAsFactors=F)
P1<-cbind(Data2[,2])
P2<-cbind(Data2[,5:30])
FinalData<-cbind(P1,P2)
write.table(FinalData ,file="FinalData.txt", sep='\t', quote=F, col.names=F,
row.names=F)
Data3<-read.table("FinalData.txt", sep='\t', header=F, stringsAsFactors=F)
m<-merge(Data1,Data3, by="V1")
--
View this message in context: http://www.nabble.com/problem-merging-two-data-sets-%28-one-with-a-header-and-one-without%29-tp19090134p19090134.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list