0

Just say I have a csv file that looks something like this:

name     number of cats
Bob            1
Janet          0
Margaret      47
Tim            2

And I load it into R doing this:

cats <- read.csv("cats.csv")

If I then open "cats" in R, I get a numbering like this:

  name     number of cats
1 Bob            1
2 Janet          0
3 Margaret      47
4 Tim            2

Similarly, if then write the csv the numbering is retained in the file.

write.csv(cats, "cats_with_numbers.csv")

I tried deleting the column, but that didn't work. Any help is appreciated. :)

B C
  • 318
  • 3
  • 16
  • 6
    In the `write.csv` you can have `row.names=FALSE` – akrun Aug 06 '15 at 21:45
  • I don't understand the question. Are you trying to rewrite the csv after doing analysis? Or do you want to print to the console without row numbers? If the latter, then `print(df, row.names = FALSE)` – Rich Scriven Aug 10 '15 at 03:37

1 Answers1

2

As akun suggested, you can use:

write.csv(cats, "cats_with_numbers.csv", row.names=FALSE)

What this is does it removes the automatic numbering of the rows.

B C
  • 318
  • 3
  • 16