Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing array to CSV, unexpected behaviour for col.names = F

Tags:

r

csv

I am trying to write an array to a CSV without the row and column names. Setting the column names to false doesnt seem to work. I get "x" for the column name and a warning.

Any ideas how to remove this "x"?

write.csv(1:5, row.names = F, col.names = F)

# "x"
# 1
# 2
# 3
# 4
# 5
# Warning message:
#   In write.csv(1:5, row.names = F, col.names = F) :
#   attempt to set 'col.names' ignored
like image 629
Deena Avatar asked Oct 18 '16 09:10

Deena


1 Answers

?write.csv tells us that among other things, for the arguments to write.csv:

append, col.names, sep, dec and qmethod cannot be altered

The way to get round this is to use the more general version, write.table.

write.table(1:5, row.names = FALSE, col.names = FALSE, sep=',')
# 1
# 2
# 3
# 4
# 5
like image 80
Miff Avatar answered Oct 22 '22 01:10

Miff