I have two dataframes in R that 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 would like to make two versions (or at least one of the two) of the new dataframe. 1) Contains the complete df1 with the addition of two new columns that overlap with 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 only the values for Genes that are in both df1 and 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))