OK I see how to remove the line numbers[1] etc by using cat instead of print, but cannot work out how to remove the column names from the data frame output

On 13/06/2010 4:21 PM, Nevil Amos wrote:
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@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.

Reply via email to