zuber at hs-heilbronn.de
2008-Nov-21 13:39 UTC
[R] write every element of a variable into a separate text-file
Hello, what I want to do, is, to write every element of a variable into a separate text-file automatically: My Variable:> wull[1] "Hallo Leute, wie gehts denn euch seid ihr noch alle..." [2] "Is their anyone how can help me with..." [3] "mann, mann, mann... das nervt aber.." [4] "how are you littele strange tiger..." [5] ")()()(UJKJKJIJIJJOO9989////////////" [6] "bradortslow, eiwudoiude, kdkdkdk:::idjidji" I was trying to do things like that:> for (i in seq(along = wull))+ write(wull[i], ("C://Users//zuber//Documents//wull(1).txt"), + append = F) But what I get is just the last element [6] ("bradortslow, eiwudoiude, kdkdkdk:::idjidji") of my variable in just one text-file. - I do not know, how to say to R, that it should write: [1] "Hallo Leute, wie gehts denn euch seid ihr noch alle..." in "wull(1).txt" [2] "Is their anyone how can help me with..." in "wull(2).txt" [3] "mann, mann, mann... das nervt aber.." in "wull(3).txt" ... an so on till the last element. I hope this is possible and someone can help me. Martin
Sarah Goslee
2008-Nov-21 15:20 UTC
[R] write every element of a variable into a separate text-file
Well, you could read the R Data Import/Export manual. Or you could reread the help for write and figure out what the append argument does. Or you could reread the help for write and notice that it should write out your entire "variable" without requiring a loop. Sarah On Fri, Nov 21, 2008 at 8:39 AM, <zuber at hs-heilbronn.de> wrote:> Hello, > > what I want to do, is, to write every element of a variable into a > separate text-file automatically: >-- Sarah Goslee http://www.functionaldiversity.org
Jagat.K.Sheth at wellsfargo.com
2008-Nov-21 15:40 UTC
[R] write every element of a variable into a separate text-file
Your code isn't changing the filename
Try this
for(i in seq_along(wull)) write(wull[i],
paste("C://Users//zuber//Documents//wull(",i,")",".txt",sep=""))
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of zuber at hs-heilbronn.de
Sent: Friday, November 21, 2008 7:39 AM
To: r-help at r-project.org
Subject: [R] write every element of a variable into a separate text-file
Hello,
what I want to do, is, to write every element of a variable into a
separate text-file automatically:
My Variable:
> wull
[1] "Hallo Leute, wie gehts denn euch seid ihr noch alle..."
[2] "Is their anyone how can help me with..."
[3] "mann, mann, mann... das nervt aber.."
[4] "how are you littele strange tiger..."
[5] ")()()(UJKJKJIJIJJOO9989////////////"
[6] "bradortslow, eiwudoiude, kdkdkdk:::idjidji"
I was trying to do things like that:
> for (i in seq(along = wull))
+ write(wull[i], ("C://Users//zuber//Documents//wull(1).txt"),
+ append = F)
But what I get is just the last element [6] ("bradortslow, eiwudoiude,
kdkdkdk:::idjidji") of my variable in just one text-file.
- I do not know, how to say to R, that it should write:
[1] "Hallo Leute, wie gehts denn euch seid ihr noch alle..." in
"wull(1).txt"
[2] "Is their anyone how can help me with..." in
"wull(2).txt"
[3] "mann, mann, mann... das nervt aber.." in "wull(3).txt"
... an so on till the last element.
I hope this is possible and someone can help me.
Martin
______________________________________________
R-help at 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.
Michael Dewey
2008-Nov-23 09:31 UTC
[R] write every element of a variable into a separate text-file
At 13:39 21/11/2008, zuber at hs-heilbronn.de wrote:>Hello, > >what I want to do, is, to write every element of a variable into a >separate text-file automatically:I think this may be FAQ 7.34 How can I save the result of each iteration in a loop into a separate file?>My Variable: > > > wull >[1] "Hallo Leute, wie gehts denn euch seid ihr noch alle..." >[2] "Is their anyone how can help me with..." >[3] "mann, mann, mann... das nervt aber.." >[4] "how are you littele strange tiger..." >[5] ")()()(UJKJKJIJIJJOO9989////////////" >[6] "bradortslow, eiwudoiude, kdkdkdk:::idjidji" > >I was trying to do things like that: > > > for (i in seq(along = wull)) >+ write(wull[i], ("C://Users//zuber//Documents//wull(1).txt"), >+ append = F) > >But what I get is just the last element [6] ("bradortslow, eiwudoiude, >kdkdkdk:::idjidji") of my variable in just one text-file. > > - I do not know, how to say to R, that it should write: > >[1] "Hallo Leute, wie gehts denn euch seid ihr noch alle..." in >"wull(1).txt" > >[2] "Is their anyone how can help me with..." in "wull(2).txt" > >[3] "mann, mann, mann... das nervt aber.." in "wull(3).txt" > >... an so on till the last element. > > >I hope this is possible and someone can help me. > > >MartinMichael Dewey http://www.aghmed.fsnet.co.uk