All, Relatively new R user so this is probably an easy question to answer. I am able to generate a cluster for my dataset using hclust() then ploting the data with plot(). This results in an image with a dendrogram with my sample names along the bottom. Great! However, I now need a way to get that sample order from the image into excel. i.e. sample 7 was on the far left, sample 19 was in position 2, sample 93 was in position 3, etc. As of now the only way for me to do this is to manually type the samples from the image into a worksheet. Very time consuming as I've got a couple hundred samples and several different dendrograms! Any thoughts? Thanks so much! -- View this message in context: http://r.789695.n4.nabble.com/Simple-Question-About-Exporting-Back-to-Excel-tp4644296.html Sent from the R help mailing list archive at Nabble.com.
Hello, In the help page for ?hclust you will see the return values. It has an element order, "a vector giving the permutation of the original observations suitable for plotting". From the first example on that page: hc <- hclust(dist(USArrests), "ave") plot(hc) ix <- hc$order rownames(USArrests)[ix] # This is the order you want Then use write.csv to write a CVS file or package XLConnect, my favorite for anything relating to excel. If you do use it, read the vignette, it will make your excel life easier. Or do the rest of the processing in R, the [much] better choice. Hope this helps, Rui Barradas Em 26-09-2012 22:11, RCar escreveu:> All, > Relatively new R user so this is probably an easy question to answer. > I am able to generate a cluster for my dataset using hclust() then ploting > the data with plot(). > This results in an image with a dendrogram with my sample names along the > bottom. Great! > However, I now need a way to get that sample order from the image into > excel. > i.e. sample 7 was on the far left, sample 19 was in position 2, sample 93 > was in position 3, etc. > As of now the only way for me to do this is to manually type the samples > from the image into a worksheet. > Very time consuming as I've got a couple hundred samples and several > different dendrograms! > Any thoughts? > > Thanks so much! > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Simple-Question-About-Exporting-Back-to-Excel-tp4644296.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.
On Wed, Sep 26, 2012 at 3:11 PM, RCar <ryan.carstens@utsouthwestern.edu>wrote:> All, > Relatively new R user so this is probably an easy question to answer. > I am able to generate a cluster for my dataset using hclust() then ploting > the data with plot(). > This results in an image with a dendrogram with my sample names along the > bottom. Great! > However, I now need a way to get that sample order from the image into > excel. >Why? What does the order of labels in a dendrogram mean ? But if you insist hc <- hclust(dist(USArrests), "ave") plot(hc) str(hc) hc$labels[hc$order] ?write.table> i.e. sample 7 was on the far left, sample 19 was in position 2, sample 93 > was in position 3, etc. > As of now the only way for me to do this is to manually type the samples > from the image into a worksheet. > Very time consuming as I've got a couple hundred samples and several > different dendrograms! > Any thoughts? > > Thanks so much! > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Simple-Question-About-Exporting-Back-to-Excel-tp4644296.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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]]
Check the return values for hclust using ?hclust (particularly the value order):> set.seed(42) > x <- matrix(rnorm(100), nrow=25) > outp <- hclust(dist(x)) > plot(outp) > outp$order[1] 9 6 16 1 7 24 25 3 14 11 12 20 18 19 23 4 10 5 17 13 22 2 15 8 21 You could use this to reorder the data set before sending it back to Excel: xnew <- x[outp$order,] ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of RCar > Sent: Wednesday, September 26, 2012 4:12 PM > To: r-help at r-project.org > Subject: [R] Simple Question About Exporting Back to Excel > > All, > Relatively new R user so this is probably an easy question to answer. > I am able to generate a cluster for my dataset using hclust() then > ploting the data with plot(). > This results in an image with a dendrogram with my sample names along > the bottom. Great! However, I now need a way to get that sample order > from the image into excel. i.e. sample 7 was on the far left, sample 19was> in position 2, sample 93 was in position 3, etc. As of now the only wayfor> me to do this is to manually type the samples from the image into aworksheet.> Very time consuming as I've got a couple hundred samples and several > different dendrograms! > Any thoughts? > > Thanks so much! > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Simple- > Question-About-Exporting-Back-to-Excel-tp4644296.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.