[R] write list to ascii
William Dunlap
wdunlap at tibco.com
Thu Jul 19 17:12:27 CEST 2012
You will probably need to write a custom function, but it could
use the built-in write.dcf() or formatDL() functions. E.g.,
> # options(width=50)
> write.dcf(list(One=paste(1:50,collapse=" "), Two=paste(state.abb[1:5], collapse=", ")))
One: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42
43 44 45 46 47 48 49 50
Two: AL, AK, AZ, AR, CA
> fx1 <- formatDL(c("One", "Two"), c(paste(1:50,collapse=" "), paste(state.abb[1:5], collapse=", ")))
> cat(fx1, sep="\n")
One 1 2 3 4 5 6 7 8 9 10 11 12 13
14 15 16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31 32 33
34 35 36 37 38 39 40 41 42 43
44 45 46 47 48 49 50
Two AL, AK, AZ, AR, CA
> fx2 <- formatDL(c("One", "Two"), c(paste(1:50,collapse=" "), paste(state.abb[1:5], collapse=", ")), style="list")
> cat(fx2, sep="\n")
One: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42
43 44 45 46 47 48 49 50
Two: AL, AK, AZ, AR, CA
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Skála, Zdenek (INCOMA GfK)
> Sent: Thursday, July 19, 2012 2:10 AM
> To: r-help at r-project.org
> Subject: [R] write list to ascii
>
> Dear all,
> apologies for this (perhaps recurrent) question but I did not found a question when
> searching mailing lists.
>
> How to write a list of a simple kind, e.g.:
>
> abc <- list(one=(1:2), two=(1:5))
>
> # to a file? I understand that write() & co. cannot work but when I try
>
> sink("aa.txt", append=T, split=T)
> abc
> sink()
>
> # the output is indeed "split by rows" in the textfile, each starting with row numbers
> (and I have rather long "vectors" resulting in many rows...):
>
> $one
> [1] 1 2
>
> $two
> [1] 1 2 3 4 5
>
> What I would need is a simple "set of vectors" starting with name in the style of:
> $one 1 2
> $two 1 2 3 4 5
>
> Is it possible in R?
>
> Many thanks!
>
> Zdenek Skala
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list