Reputation: 417
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 .
Upvotes: 15
Views: 87551
Reputation: 11
You can use what ever delimiter you want, also note that you can use a string as a delimiter. So some non-standard examples might be "||" or "|/|". This is particularly helpful if one of the fields already contains some other kinds of delimiters such as ";" "," ":", or "|".
Upvotes: 1
Reputation: 71
I would be inclined to use qmethod = "double"
and therefore the separators don't interfere with field content.
Upvotes: 1
Reputation: 18749
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"
.
Upvotes: 26