Search code examples
rdataframequotes

How to save character data from table/dataframe without double quotes as csv or txt file in R?


When a file containing a table or dataframe with character values has been created in R using write.table() or write.csv(), but is opened on a text editor, the values are all in double quotes in the text editor, for example

"MM","M786"
"MM","M797"
"MM","M801"

Is there a way to save the table or dataframe in R so that the double quotes do not show when opening the file with a text editor? So it shoud be

MM,M786 
MM,M797  
MM,M801

Thanks!


Solution

  • Use quote = FALSE -

    write.csv(df, 'out.csv', row.names = FALSE, quote = FALSE)
    write.table(df, 'out.txt', quote = FALSE, row.names = FALSE)