[R] How to write a data.frame into n different csv-files
Chuck Cleland
ccleland at optonline.net
Mon Jul 16 11:35:34 CEST 2007
Dr. Guido Möser wrote:
> Hello,
>
>
> I want to write a data.frame with 10 different entries x (by index y)? into ten different csv-files.
> In every output file should be one of the ten numbers of x.
>
>
> I tried this one, but I can't write into ten different files, like test1.csv to test10.csv:
>
>
> x <- rnorm(10)
> y <- c(1:10)
> z <- data.frame(y,x)
>
> n <- nrow(z)
> for (i in 1:n) write.csv(z$x[i], file="test[i].csv")
>
>
> Can anyone help me?
Try this:
x <- rnorm(10)
y <- c(1:10)
z <- data.frame(y,x)
n <- nrow(z)
for (i in 1:n) write.csv(z$x[i], file=paste("test", i, ".csv", sep=""))
> Yours,
>
>
>
> Guido
>
>
>
> ---
> Dr. Guido Moeser
> Diplom Volkswirt
> Diplom Sozialwissenschaftler
>
> E-Mail: GMoeser at aol.com
>
> ________________________________________________________________________
> Bei AOL gibt's jetzt kostenlos eMail f?r alle. Klicken Sie auf AOL.de um heraus zu finden, was es sonst noch kostenlos bei AOL gibt.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list