I have a data frame df with about 50 columns and 20.000 rows. It looks like the data frame below:
Date P1 P2 P3 P4
1/1/2000 0 0.4 0 0
2/1/2000 0 0.1 0 0.1
3/1/2000 0.5 0 0 1
4/2000 0.8 1.5 1 1
How can I export every (numeric) column to a text file?
(except for the Date column, which I could remove/subset/delete from df)
I would like the text file to have the same name as the column header.
P1.txt:
0
0
0.5
0.8
P2.txt:
0.4
0.1
0
1.5
etc.
This what I have so far, for 50 columns:
df$Date<-NULL
for(i in c(1:32)){
write.table(df[,i],file=paste0(names(df)[i],row.names = FALSE, col.names = FALSE, ".txt"))
}
however the generated output is: P1.txt:
"P1"
"1" 0
"2" 0
"3" 0.5
"4" 0.8
is it possible to get rid of this first column"1","2","3","4" and header "P1"?