简体   繁体   中英

How to delete some column based on the column headings of a csv file in R?

  1. I have loaded a csv file to R.

  2. There are 10 columns in the file.

  3. I want to save the 1st 3rd and 5th column to a new file. What is the command line to delete other columns?

  4. I want to save the new table, what is the command line should be used?

First, I'll answer your question. If d is your data frame loaded from your file, then:

d_subset = d[,c(1,3,5)]
write.csv(d_subset, file="file.csv")

Second, I'll give you some advice. Read the documentation or buy a good R book. You can even download An introduction to R for free. Many of the questions you are asking are very basic. While most people are happy to handle the odd basic question, asking three or four a day really isn't sustainable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM