[R] Export cols to single csv files
B77S
bps0002 at auburn.edu
Sun Dec 4 18:55:13 CET 2011
just use indexing.
without doing it all for you...
df <- structure(list(AA = c(0.3, 0.1, 0.6), BB = c(0.9, 0.4, 0.2),
CC = c(1, 0.8, 0.6), DD = c(0.7, 0.5, 0.5)), .Names = c("AA",
"BB", "CC", "DD"), class = "data.frame", row.names = c(NA, -3L
))
write.csv(df[,1], paste(colnames(df[1]), "csv", sep="."))
Chega wrote
>
> Hi
>
> I am trying to "batch export" the columns of a numeric matrix to separate
> csv files by naming them according to the column names.
>
> So my matrix in R looks like this:
> AA BB CC DD etc.
> 1: 0.3 0.9 1.0 0.7 ...
> 2: 0.1 0.4 0.8 0.5 ...
> 3: 0.6 0.2 0.6 0.5 ...
> etc.
>
> Now I am looking for a way to get these files (file names in quotes):
>
> "AA.csv" "BB.csv" "CC.csv" etc.
> 1: 0.3 1: 0.9 1: 1.0
> 2: 0.1 2: 0.4 2: 0.8
> 3: 0.6 3: 0.2 3: 0.6
> etc. etc. etc.
>
> As I understand this may be done using write.csv and a loop with the
> column names, but I have no idea how to export single columns.
>
> Thanks i.a. for help!
> Chega
>
--
View this message in context: http://r.789695.n4.nabble.com/Export-cols-to-single-csv-files-tp4157484p4157537.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list