Hello,
I am looking for a way to transform an array into a list (or a string).
My array has two columns 1 and 2, and I would like to create a list of the
values.
Let's say I have :
x1 x2
1 a b
2 c d
3 e f
4 g h
What I would like to obtain is a,b,c,d,e,f,g,h.
I tried without success melt and reshape ( reshape(my_array,
direction="long", varying=1:2) ) but I cannot get it work.
Thanks a lot !!!
thomas
--
View this message in context: http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4418804.html
Sent from the R help mailing list archive at Nabble.com.
Table into a list
6 messages · thomas88, Rui Barradas, R. Michael Weylandt +1 more
Hello, Try (d <- data.frame(x1=letters[2*1:4 - 1], x2=letters[2*1:4])) c(apply(d, 1, identity)) Note that you'll need the concatenation 'c()'. Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4419091.html Sent from the R help mailing list archive at Nabble.com.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120225/ea18b4e1/attachment.pl>
Your question is not well formed: do you want a list or a string (totally different things)? Or even more likely, a character vector? What do you have now: is it really an array (=matrix) or is it the data.frame it looks like? If it's a matrix: x <- matrix(letters[1:8], ncol = 2) x <- as.vector(x) # Character Vector paste(x, collapse = "") # String If it's a data frame with factors: x <- data.frame(matrix(letters[1:8], ncol = 2)) as.character(unlist(x)) # omit as.character() if you actually have character elements and not factors. Michael
On Fri, Feb 24, 2012 at 5:32 PM, thomas88 <thomas.coquet at free.fr> wrote:
Hello, I am looking for a way to transform an array into a list (or a string). My array has two columns 1 and 2, and I would like to create a list of the values. Let's say I have : ? ? ? x1 ? ? ? x2 1 ? ? ?a ? ? ? ? ?b 2 ? ? ?c ? ? ? ? ?d 3 ? ? ?e ? ? ? ? ?f 4 ? ? ?g ? ? ? ? ?h What I would like to obtain is a,b,c,d,e,f,g,h. I tried without success melt and reshape ( reshape(my_array, direction="long", varying=1:2) ) but I cannot get it work. Thanks a lot !!! thomas -- View this message in context: http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4418804.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.
My apologies: I missed the order of the desired output: the easiest thing to do is likely to use the same techniques given below (and by others in this thread) with a transpose t() before. Michael On Sat, Feb 25, 2012 at 2:05 AM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
Your question is not well formed: do you want a list or a string (totally different things)? Or even more likely, a character vector? What do you have now: is it really an array (=matrix) or is it the data.frame it looks like? If it's a matrix: x <- matrix(letters[1:8], ncol = 2) x <- as.vector(x) # Character Vector paste(x, collapse = "") # String If it's a data frame with factors: x <- data.frame(matrix(letters[1:8], ncol = 2)) as.character(unlist(x)) # omit as.character() if you actually have character elements and not factors. Michael On Fri, Feb 24, 2012 at 5:32 PM, thomas88 <thomas.coquet at free.fr> wrote:
Hello, I am looking for a way to transform an array into a list (or a string). My array has two columns 1 and 2, and I would like to create a list of the values. Let's say I have : ? ? ? x1 ? ? ? x2 1 ? ? ?a ? ? ? ? ?b 2 ? ? ?c ? ? ? ? ?d 3 ? ? ?e ? ? ? ? ?f 4 ? ? ?g ? ? ? ? ?h What I would like to obtain is a,b,c,d,e,f,g,h. I tried without success melt and reshape ( reshape(my_array, direction="long", varying=1:2) ) but I cannot get it work. Thanks a lot !!! thomas -- View this message in context: http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4418804.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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120225/9712e1bb/attachment.pl>