[R] How to output text to sink without initial line number [1], and data frame line by line without column names

From: Nevil Amos <nevil.amos_at_gmail.com>
Date: Sun, 13 Jun 2010 16:21:12 +1000


I want to output a text file assembeld from various soruces within r ( actually as a genepop file)

the output should be formatted     line 1 "text comment"
                                                    line 2:n  selected 
column names from data frame
                                                     line n+1on lines of 
selected columns from data frame one row at a time

I have the following code, but cannot see how to remove the line numbers and omit column names form the line by line data frame output

col1<-c(2,45,67)
col2<-c("a","B","C")
col3<-c(234,44,566)
mydf<-as.data.frame(cbind(col1,col2,col3))
n<-ncol(mydf)
nr<-nrow(mydf)
sink("test.txt")

print("I will be including text of various sorts in this file so cannot use print table or similar command")
for (i in 1:n){
print(colnames(mydf[i]),quote=F) }
for (j in 1:nr){
print(mydf[j,c(2:n)],quote=F,row.names=F)} sink()

The test.txt contains:

[1] "I will be including text of various sorts in this file so cannot
use print table or similar command"
[1] col1
[1] col2
[1] col3

  col2 col3

     a 234
  col2 col3

     B 44
  col2 col3

     C 566

what I would like in test.txt is:

"I will be including text of various sorts in this file so cannot use print table or similar command"
col1
col2
col3
  a 234
  B 44
  C 566

Many thanks

Nevil Amos



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 13 Jun 2010 - 06:23:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 Jun 2010 - 07:00:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive