1
  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?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Catherine
  • 5,095
  • 11
  • 29
  • 27
  • 7
    R comes with *six manuals*. One is a general introduction explaining point three about indexing. Another one is on data import/export and covers point four. – Dirk Eddelbuettel Apr 06 '11 at 14:59

1 Answers1

12

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.

csgillespie
  • 57,032
  • 13
  • 142
  • 178
  • 10
    +1 for _While most people are happy to handle the odd basic question, asking three or four a day really isn't sustainable._ – Joshua Ulrich Apr 06 '11 at 15:08