Re: [R] how to convert a data.frame to tree structure object such as dendrogram

2013-03-13 Thread Bert Gunter
Here is a simpler, less clumsy version of my previous recursive R solution that I sent you privately, which I'll also cc to the list this time. It's now almost a one-liner. To avoid problems with unused factor levels, I still prefer to have character vectors not factors, as the data frame columns

Re: [R] how to convert a data.frame to tree structure object such as dendrogram

2013-03-12 Thread David Winsemius
On Mar 12, 2013, at 9:37 AM, Not To Miss wrote: > Thanks. Is there any more elegant solution? What if I don't know how many > levels of nesting ahead of time? It's even worse than what you now offer as a potential complication. You did not provide an example of a data object that would illustra

Re: [R] how to convert a data.frame to tree structure object such as dendrogram

2013-03-12 Thread Not To Miss
Thanks. Is there any more elegant solution? What if I don't know how many levels of nesting ahead of time? On Tue, Mar 12, 2013 at 8:51 AM, Greg Snow <538...@gmail.com> wrote: > You can use the lapply or rapply functions on the resulting list to break > each piece into a list itself, then apply

Re: [R] how to convert a data.frame to tree structure object such as dendrogram

2013-03-12 Thread Greg Snow
You can use the lapply or rapply functions on the resulting list to break each piece into a list itself, then apply the lapply or rapply function to those resulting lists, ... On Mon, Mar 11, 2013 at 3:41 PM, Not To Miss wrote: > Thanks. That's just an simple example - what if there are more co

Re: [R] how to convert a data.frame to tree structure object such as dendrogram

2013-03-11 Thread Not To Miss
Thanks. That's just an simple example - what if there are more columns and more rows? Is there any easy way to create nested list? Best, Zech On Mon, Mar 11, 2013 at 2:12 PM, MacQueen, Don wrote: > You will have to decide what R data structure is a "tree structure". But > maybe this will get y

Re: [R] how to convert a data.frame to tree structure object such as dendrogram

2013-03-11 Thread Bert Gunter
Of course, R's recursive lists **are** trees. (Some expert may rap my knuckles here, but ... close enough?) -- Bert On Mon, Mar 11, 2013 at 1:12 PM, MacQueen, Don wrote: > You will have to decide what R data structure is a "tree structure". But > maybe this will get you started: > >> foo <- dat

Re: [R] how to convert a data.frame to tree structure object such as dendrogram

2013-03-11 Thread MacQueen, Don
You will have to decide what R data structure is a "tree structure". But maybe this will get you started: > foo <- data.frame(x=c('A','A','B','B'), y=c('Ab','Ac','Ba','Bd')) > split(foo$y, foo$x) $A [1] "Ab" "Ac" $B [1] "Ba" "Bd" I suppose it is at least a little bit tree-like. -- Don MacQuee