[R] Transfering data from R list to other document format
David Winsemius
dwinsemius at comcast.net
Tue May 15 16:55:58 CEST 2012
On May 15, 2012, at 6:56 AM, pannigh wrote:
> Dear users,
> I want to transfer a list of results from R to some practical
> format, from
> where I can continue manipulating, copying,... the values, e.g. :
>
> list1 <- list("My first list", matrix(1:6, ncol=3), c(1,2,3,4,5,6) )
> # Imagining I forgot something and want to add it to the list like:
> list1[[4]] <- list(c(4,4,4), "This is it")
> # Now I want to transfer the list to e.g. a text document:
> lapply(L1, write, "test.txt", append=TRUE, ncolumns=100)
>
> However, this does not work and I don't know why.
Two reasons:
The glaringly obvious error is that you have constructed 'list1' and
then called lapply with an argument of 'L1'.
The more difficult error to see is that 'write' will not accept a list
of lists, which is what your fourth element. Using a recursive apply
function can help. Try either on of these:
> rapply(list1, function(x) { cat(c(x, "\n"), file="test.txt",
append=TRUE) })
NULL
> rapply(list1, function(x) { write(x, file="test.txt", append=TRUE) })
NULL
>
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list