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. Also I would be interested in better options to get lists out of R (with tables I never had any problems). Thank you for your help and ideas! -- View this message in context: http://r.789695.n4.nabble.com/Transfering-data-from-R-list-to-other-document-format-tp4630057.html Sent from the R help mailing list archive at Nabble.com.
Jeff Newmiller
2012-May-15 13:41 UTC
[R] Transfering data from R list to other document format
Well, dput() can do this, but if your goal is exchange with other analysis packages then you need to decide whether transforming to XML or to a tabular form meets your needs better. For the latter, you might consider the ldply function from the plyr package. You may benefit from reading the Data Input/Output documentation for R. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. pannigh <pannigh at gwdg.de> 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. Also I would be >interested >in better options to get lists out of R (with tables I never had any >problems). > >Thank you for your help and ideas! > >-- >View this message in context: >http://r.789695.n4.nabble.com/Transfering-data-from-R-list-to-other-document-format-tp4630057.html >Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >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.
David Winsemius
2012-May-15 14:55 UTC
[R] Transfering data from R list to other document format
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