bioinformatics - Partially Merging Data Sets in R -
i have 2 data files this:
bin chrom chromstart chromend name score strand 23 chr1 119537649 119537708 a_14_p109202 1000 + 109 chr1 37879762 37879821 a_16_p15088121 1000 + 129 chr1 59113425 59113484 a_16_p00074945 1000 + 138 chr1 68288459 68288517 a_16_p00088142 1000 +
and
hybridization ref tcga-02-0001-01c-01d-0185-02 composite element ref normalizedlog2ratio a_14_p112718 0.034472223 a_16_p15000916 -0.038733669 a_16_p15001074 -0.498562753 a_16_p00000012 -0.269915751
.
using names first column of second file, need extract additional data data table in first file. however, not every name in second file appears in first. having problems getting files merge properly. appreciated.
if place all.x=true
in merge command; of records first data frame in merged dataframe, if don't have match in second. problem encountering? in example gave none of rownames matched of observations in name variable.
bin<-c(23,109,129,138) chrom<-c("chr1","chr1","chr1","chr1") chromstart<-c(119537649,37879762,59113425,68288459) name<-c("a_14_p109202", "a_16_p15088121", "a_16_p00074945","a_16_p00088142") b<- data.frame(cbind(bin,chrom,chromstart,name)) y <- data.frame(c(0.034472223 ,-0.038733669 , -0.498562753 ,-0.269915751)) rownames(y)<-c("a_14_p112718","a_16_p15000916","a_16_p15001074","a_16_p00000012") print(b) print(y) #check rows nrow(b) nrow(y) #write rownames new variable y$name <- rownames(y) #conduct merge newdataframe <- merge(b, y, by=("name"), all.x = true ) #check number of rows nrow(newdataframe)
Comments
Post a Comment