Skip to content
Prev 44933 / 398528 Next

adding header info to write.table

A minor variant is to use "cat" for the initial headers: 

DF <- data.frame(a=1:2, b=c("a","B"))
cat("header1\nheader2\n", file="filename.csv")
cat("header3\n", file="filename.csv", append=TRUE)
write.table(DF, file="filename.csv", append=TRUE)

      In S-Plus 6.2 and R 1.8.2, this produces the following: 

header1
header2
header3
"a" "b"
"1" 1 "a"
"2" 2 "B"

      hope this helps.  spencer graves
Liaw, Andy wrote: