How to generate file (.csv) with 51 specific columns from file (tab delimited .txt file) containing 17,384 columns

Having 17,384 columns in this .txt file, I can't use Excel, which has a 16,384 column limit, to pull out 51 specific columns to do some very simple calculations. I'm brand new to R and spent the whole day today trying to use R Console, R Studio, and R Commander, but had no luck. I would appreciate it if someone can share with me the script. Many thanks!

You do not provide many details, so I will give a general answer.
To read in the file, assuming it has headers,

DF <- read.csv("Path/To/Your/File.txt", sep = "\t", header = TRUE)

To pick out columns 3, 7, and 23 by position

DFselect <- DF[, c(3,7,23)]

To pick out columns by name, assuming names of Location, Date, and Data3

DFselect <- DF[, c("Location", "Date", "Data3")]

To save the file

write.csv(DFselect, file = "Path/To/The/Location.csv", row.names = FALSE)

My column headings had hyphens in them (ex. "GTEX-11DXX-1526-SM-5H115") so it took me 4 hours to troubleshoot and fix, but it worked! Thank you!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.