---+ Writing a list of vectors to a file Suppose you have a list whose components are vectors of different length, such as: <highlight> a <- list(comp1 = 1:2, comp2 = 3:6, comp3 = 7:9) </highlight> Here's how you can write the list to a file such that each component occupies a _row_ of the output file --- therefore, the output file has a different number of columns for each row. <highlight> cat(sapply(a, paste, collapse = "\t"), sep = "\n", file = "filename.txt") </highlight> In the previous code, we first collapse the elements of each vector to be tab delited (="\t"=), and then we write each vector to the file as separate rows (="\n"=).
This topic: Main
>
WebHome
>
Seminars
>
RClinic
>
WritingVectorList
Topic revision:
21 Nov 2006,
TheresaScott
(raw view)
Copyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki?
Send feedback