[R] combine words and dataframe

Dieter Menne dieter.menne at menne-biomed.de
Thu Apr 9 10:59:27 CEST 2009


Ravi S. Shankar <ravis <at> ambaresearch.com> writes:

> I am trying to get an output like this
> Hi
> Hello
> 1           a           b

# The easy way: good for logging of results, but commands print too,
# depending how you run it
df = data.frame(a=rep("a",3),b=rep("b",3))
sink(file="a.txt")
cat("Hello\n")
print(df)
sink()

# a bit better
cat("Hello\n",file="b.txt")
write.table(df,file="b.txt",append=TRUE,col.names=FALSE,
  row.names=FALSE,quote=FALSE)


Dieter




More information about the R-help mailing list