An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130310/ec2944d7/attachment.pl>
how to convert a data.frame to tree structure object such as dendrogram
7 messages · MacQueen, Don, Bert Gunter, Not To Miss +2 more
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 MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 3/10/13 9:19 PM, "Not To Miss" <not.to.miss at gmail.com> wrote:
>I have a data.frame object like:
>
>> data.frame(x=c('A','A','B','B'), y=c('Ab','Ac','Ba','Bd'))
> x y
>1 A Ab
>2 A Ac
>3 B Ba
>4 B Bd
>
>how could I create a tree structure object like this:
> |---Ab
> A---|
>_| |---Ac
> |
> | |---Ba
> B---|
> |---Bb
>
>Thanks,
>Zech
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>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.
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 <macqueen1 at llnl.gov> wrote:
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 MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 3/10/13 9:19 PM, "Not To Miss" <not.to.miss at gmail.com> wrote:
I have a data.frame object like:
data.frame(x=c('A','A','B','B'), y=c('Ab','Ac','Ba','Bd'))
x y
1 A Ab
2 A Ac
3 B Ba
4 B Bd
how could I create a tree structure object like this:
|---Ab
A---|
_| |---Ac
|
| |---Ba
B---|
|---Bb
Thanks,
Zech
[[alternative HTML version deleted]]
______________________________________________ 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.
______________________________________________ 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.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130311/700418d2/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130312/37762329/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130312/9794dc3b/attachment.pl>
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 illustrate the complexity of the task nor what you consider the correct procedure (i.e. the order of the columns to be used for splitting) nor the correct results. The task is woefully underspecified at the moment. It's a bit akin to asking "how do I do classification" without saying what you what to classify.
David.
>
>
> On Tue, Mar 12, 2013 at 8:51 AM, Greg Snow <538280 at 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 the lapply or rapply function to
>> those resulting lists, ...
>>
>>
>> On Mon, Mar 11, 2013 at 3:41 PM, Not To Miss <not.to.miss at gmail.com>wrote:
>>
>>> 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 <macqueen1 at llnl.gov>
>>> wrote:
>>>
>>>> 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 MacQueen
>>>>
>>>> Lawrence Livermore National Laboratory
>>>> 7000 East Ave., L-627
>>>> Livermore, CA 94550
>>>> 925-423-1062
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On 3/10/13 9:19 PM, "Not To Miss" <not.to.miss at gmail.com> wrote:
>>>>
>>>>> I have a data.frame object like:
>>>>>
>>>>>> data.frame(x=c('A','A','B','B'), y=c('Ab','Ac','Ba','Bd'))
>>>>> x y
>>>>> 1 A Ab
>>>>> 2 A Ac
>>>>> 3 B Ba
>>>>> 4 B Bd
>>>>>
>>>>> how could I create a tree structure object like this:
>>>>> |---Ab
>>>>> A---|
>>>>> _| |---Ac
>>>>> |
>>>>> | |---Ba
>>>>> B---|
>>>>> |---Bb
>>>>>
>>>>> Thanks,
>>>>> Zech
>>>>>
>>>>> [[alternative HTML version deleted]]
>>>>>
>>>>> ______________________________________________
>>>>> 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.
>>>>
>>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>>
>>
>> --
>> Gregory (Greg) L. Snow Ph.D.
>> 538280 at gmail.com
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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
Alameda, CA, USA