[R] a question on write.table
Antonio Silva
aolinto.lst at gmail.com
Mon Sep 28 20:31:38 CEST 2015
Dear R users
I want to write a file that contains several data frames generated in a loop
ing.
I also want the column names be written to file only when it is created in
first loop.
In the example below, when I run each line separately without "for (i in
...) { }" it works, but when I run the looping I get an error message
X<-c("A","B","C","D","E")
Y<-c(0,1,2,3,4)
for (i in 0:3) {
Y<-Y+i
data<-data.frame(X,Y)
ifelse(file.exists("test.csv"),
write.table(data,"test.csv",row.names =
FALSE,col.names=FALSE,sep=";",append=TRUE),
write.table(data,"test.csv",row.names = FALSE,sep=";")
)}
Error in ifelse(file.exists("test.csv"), write.table(data, "test.csv", :
substituto tem comprimento zero
Além disso: Warning message:
In rep(yes, length.out = length(ans)) :
'x' is NULL so the result will be NULL
What is going wrong here? Thanks for any comments or suggestions.
All the best.
Antonio Olinto
[[alternative HTML version deleted]]
More information about the R-help
mailing list