Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write to csv file using separator

Tags:

r

I want to write my resulted matrix into csv file.

I used the code

write.table(result, file ="F:\\filename.csv",row.names=FALSE,sep=",")

But my results already having some "," value,so what type of separator use to write these type of data.

I already used 'tab' as the separator but at that time it did not split as column, the values were inserted into a single column.

I also tried

  write.csv(result, file ="F:\\filename.csv",row.names=FALSE)

but this time the single column content is splited into multiple column .

like image 851
user1790894 Avatar asked Dec 07 '12 07:12

user1790894


1 Answers

In countries where , is used as a decimal separator (France and Germany for example), "csv" files are actually semi-colon separated (it is the default on all spreadsheet program if you install those countries specific version).
So write.table(result, file ="F:\\filename.csv",row.names=FALSE,sep=";") would be quite classic.
So classic actually that there is a wrapper for it:

write.csv2(result, file ="F:\\filename.csv",row.names=FALSE)

write.csv2 use sep=";" and dec="," as default.

Otherwise for a tab-delimited files the argument is sep="\t".

like image 159
plannapus Avatar answered Oct 14 '22 21:10

plannapus