Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete "" from csv values and change column names when writing to a CSV

Tags:

r

csv

I'm trying to create csv files out of an R table. But i cant understand why all the values get checked with "" when i use the write.csv() function. my data looks like this:

        Sample  Sample_Name Sample_Group    Pool_ID Sample_Plate    NorTum  Sentrix_ID    Sentrix_Position  HybNR     1   00_11242    00_24200N2  MUTYH   GS0005703-OPA   GS0010004-DNA   N     1280307   R007_C005   1     2   00_11242    00_24200N2  MUTYH   GS0005704-OPA   GS0010004-DNA   N   1280307 R007_C011   1     3   00_11242    00_24200N2  MUTYH   GS0005702-OPA   GS0010004-DNA   N   1416198 R007_C011   2     4   00_11242    00_24200N2  MUTYH   GS0005701-OPA   GS0010004-DNA   N   1416198 R007_C005   2     5   00_7    00_7T   MUTYH   GS0005701-OPA   GS0010004-DNA   T   1416198 R006_C005   2     6   00_7    00_7T   MUTYH   GS0005702-OPA   GS0010004-DNA   T   1416198 R006_C011   2     7   00_7    00_7T   MUTYH   GS0005704-OPA   GS0010004-DNA   T   1280307 R006_C011   1     8   00_7    00_7T   MUTYH   GS0005703-OPA   GS0010004-DNA   T   1280307 R006_C005   1     9   01_677  01_677N HNPCC_UV    GS0005701-OPA   GS0010004-DNA   N   1416198 R002_C006   2     10  01_677  01_677N HNPCC_UV    GS0005704-OPA   GS0010004-DNA   N   1280307  

And in the output file which is a CSV every value looks like this:

"100" "R05_80611" "R05_80611N" "NA_FAM" "GS0005701-OPA" "GS0010004-DNA" "N" 1416198 "R003_C006" 2 

Why is the function putting quotes around my values and is there a way to quickly do this.

I'm also wondering how I can change my column names when writing to CSV files but since i`m a starter I've no clue on how to do this.

like image 727
Sanshine Avatar asked Jun 27 '12 09:06

Sanshine


People also ask

How do I drop a column while reading a CSV file?

Using df= df. drop(['ID','prediction'],axis=1) made the work for me. I dropped 'ID' and 'prediction' columns. Make sure you put them in square brackets like ['column1','column2'] .


1 Answers

See manual write.table {utils}.

help(write.csv)  write.csv(X, quote = FALSE) 

The justification for quoting the fields by default is that unquoted fields containing commas will be misinterpreted.

like image 199
Colonel Panic Avatar answered Sep 18 '22 22:09

Colonel Panic