I want to create a myID dataframe which contains columns SNP, trait, protein, protein.x, protein.y, metabolite, metabolite.x, metabolite.y of merged. The following code works:
myID <- subset(merged, select = c(SNP, trait, protein, protein.x, protein.y, metabolite, metabolite.x, metabolite.y))
However, I would like this to work with a piece of code that doesn't need all the colnames to be written out (as I later need to select 100+ columns).
Something like starts_with("SNP","trai","protei","metabolit") would be perfect (this doesn't work)
My data:
dput(merged[1:4,])
structure(list(SNP = c("rs1001567", "rs1002076", "rs1002365",
"rs1002480"), trait = c("complex", "complex", "complex", "complex"
), beta_g = c(-0.0021, 2e-04, -0.0141, -0.0082), df_g = c(699247, 709315, 708183, 695786
), protein.x = c("IL16", "IL16",
"IL16", "IL16"
), beta_p.x = c(-0.0874, 0.0335, -0.0268, 0.0923), df_p.x = c(3392, 3392, 3392, 3392),
protein.y = c("IL18", "IL18",
"IL18", "IL18"
), beta_p.y = c(-0.0542, 0.0257, 0.0124, 0.0846), df_p.y = c(3392, 3392, 3392, 3392
), protein = c("IL6", "IL6",
"IL6", "IL6"
), beta_p = c(0.0323, 0.0371, -0.0368, 6e-04), df_p = c(3392, 3392, 3392, 3392),
metabolite.x = c("Ile", "Ile",
"Ile", "Ile"), beta_m.x = c(0.006018,
-0.01177, 0.008134, 0.001025), df_m.x = c(21354, 23576, 21355,
23577), metabolite.y = c("Leu", "Leu",
"Leu", "Leu"), beta_m.y = c(0.010107,
-0.000184, 0.017055, -0.000436), df_m.y = c(21306, 23528, 21306,
23530), metabolite = c("Val", "Val",
"Val", "Val"), beta_m = c(0.007908,
-0.002337, 0.01489, 0.0028), df_m = c(21478, 23700, 21479,
23704)), .internal.selfref = <pointer: (nil)>, sorted = "SNP", row.names = c(NA,
4L), class = c("data.table", "data.frame"))