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

后端 未结 1 1317
难免孤独
难免孤独 2021-01-27 03:20
  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 c

相关标签:
1条回答
  • 2021-01-27 03:35

    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.

    0 讨论(0)
提交回复
热议问题