0

I am importing a csv file with read_csv() using the following command:

motus <- read_csv("motus_tables/TEST_metabar_motus_miseq_nov_12S.csv", 
                  col_names = TRUE,
                  progress = show_progress())

The issue is that this adds a first column X1 with numbers for the rows. I don't know why and I don't know how to fix it! I am trying to use this option instead of the read.table because the file I will have to read is huge and the read.table takes forever. I take any other suggestions as well to handle large csv files fast, with a progress bar being a plus!

I am running R v.3.6.2 in RStudio v.1.3

Rachel
  • 73
  • 7
  • 2
    Without seeing the data it's difficult to know why. Have you tried `vroom()` or `fread()` https://stackoverflow.com/questions/3397885/how-do-you-read-in-multiple-txt-files-into-r/48105838#48105838? – Tung Nov 21 '20 at 20:44
  • ugh, so i think i'm having trouble figuring out the rownames situation and how to save the files. for the file above, my rownames were numbers, so when writing it to csv (write.csv) it would create a first column with numbers indeed. if i assign a column as rownames, when i read the file (read_csv) it creates the first column with that column that i assigned as rowname. however, for some reason, i have another data.frame that was written and read the same way, but when reading (read_csv) it replaces my rownames to numbers! it does not add it as an extra column. – Rachel Nov 24 '20 at 04:29
  • 1
    See the `column_to_rownames()` function in the "tibble" package, this might help. My advice is leave the row names as numbers, use the first column for labels (if necessary) and use "row.names =FALSE" when using `write.csv()` – Dave2e Nov 25 '20 at 00:37
  • thanks... yeah, i agree. i'm just gonna do the column_to_rownames afterwards. i was trying to avoid multiple steps because the data is so big, but i think this is the easiest. and thanks for the tip on writing the csv. that's helpful! :) – Rachel Nov 25 '20 at 04:37

0 Answers0