merge - R merging 2 tables based on column -



merge - R merging 2 tables based on column -

this question has reply here:

how bring together (merge) info frames (inner, outer, left, right)? 10 answers

i have 2 dataframes in r contain 3 columns:

df1 <- data.frame("gene"=c("myc", "rad", "meg", "cdc"), "meth"=c(13, 62, 62, 79), "exp"=c(-4.2, 1, 0.9, -2)) df2 <- data.frame("gene"=c("rad", "gnas", "meg", "klm"), "meth"=c(54, 13, 05, 84), "exp"=c(-3.2, 0, 3.9, -2))

i create 2 versions (or @ to the lowest degree 1 of two) of new dataframe. 1) contains finish df1 add-on of 2 new columns overlap df2 gene columns, such that:

df3 <- data.frame("gene"=c("myc", "rad", "meg", "cdc"), "meth"=c(13, 62, 62, 79), "exp"=c(-4.2, 1, 0.9, -2), "meth2"=c(na, 54, 05, na), "exp2"=c(na, -3.2, 3.9, na))

2) contains values genes in both df1 , df2:

df3 <- data.frame("gene"=c("rad", "meg"), "meth"=c(62, 62), "exp"=c(1, 0.9), "meth2"=c(54, 05), "exp2"=c(-3.2, 3.9))

you can utilize merge (also have here):

> merge(df1, df2, by="gene", all.x=t) gene meth.x exp.x meth.y exp.y 1 cdc 79 -2.0 na na 2 meg 62 0.9 5 3.9 3 myc 13 -4.2 na na 4 rad 62 1.0 54 -3.2 > merge(df1,df2, = "gene") gene meth.x exp.x meth.y exp.y 1 meg 62 0.9 5 3.9 2 rad 62 1.0 54 -3.2

r merge data.frame

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -