Reputation: 1680
What is the proper way to append col names to the header of csv table which is generated by write.table
command?
For example write.table(x, file, col.names= c("ABC","ERF"))
throws error saying invalid col.names specification
.Is there way to get around the error, while maintaining the function header of write.table
.
Edit:
I am in the middle of writing large code, so exact data replication is not possible - however, this is what I have done:
write.table(paste("A","B"), file="AB.csv", col.names=c("A1","B1"))
, I am still getting this error Error in write.table(paste("A","B"), file="AB.csv", col.names=c("A", : invalid 'col.names' specification.
Upvotes: 4
Views: 22179
Reputation: 2359
Is that what you expect, tried my end
df <- data.frame(condition_1sec=1)
df1 <- data.frame(susp=0)
write.table(c(df,df1),file="table.csv",col.names = c("A","B"),sep = ",",row.names = F)
Upvotes: 9