R: Write ASCII file where column names (header) is separated differently than all other rows

I'm struggling with an export of a data frame to an ASCII file. I basically want it to look like this:

<Date> <Stock> <Price>
19900101, SOMESTOCK, 100.00
19900102, SOMESTOCK, 101.00 

How would I do that? What I have so far is:

write.table(MyDataFrame, file=File, row.names=FALSE, col.names=TRUE, sep=",")

Answers


If you want that very exact output (i.e. column names between less-than and greather-than signs, separated by spaces and content separated by commas), then:

a <- data.frame(Date=1:2,Stock=letters[1:2],Price=runif(2)) #A test case
file <- "a.txt"
cat(paste("<",colnames(a),">",sep=""),"\n",file=file) 
write.table(a, file=file, row.names=FALSE, col.names=FALSE, sep=", ",
               append=TRUE, quote=FALSE)

Note the use of argument append=TRUE in write.table and the use of argument file in cat.


Need Your Help

How to respond to duplicate e-mail address during registration

security user-input

I have a registration form in my website. I don't want to give away information about the existence of an e-mail address for security reasons. How should we, security wise, handle the "e-mail already