I need to extract many columns from a dataset. I have a very large csv file with thousands of columns and rows. In R for example, I can read it in using:
mydata <- read.csv(file = "file.csv",header = TRUE,sep = ",",row.names = 1)
Each column is a gene name. I know how to extract specific columns from my R data.frame by using the basic code like this:
mydata[ , "GeneName1", "GeneName2"]
But my question is, how do I pull hundreds of gene names? Too many to type in? They are listed in a txt file.
I've used grep in UNIX before to pull multiple ROWS using a txt file with the list of genes I need, but I haven't been able to figure out how to do it with Columns.
Can you transpose the data frame and extract the resulting rows?
supposing there is a column Gene in your new t_mydata data frame
Please use the formatting bar (especially the
code
option) to present your post better. You can use backticks for inline code (`text` becomestext
), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.