If I have an n1 x n1 x 2 array X I can calculate, say, X[,,1]/X[,,2]. If it is a 4 dimensional array then I want to be able to calculate X[,,,1]/X[,,,2], and similarly for higher dimensions. How can I write a function to do this in a general way without having to do a switch for each possible length(dim(X)). So I want a function g that will take an arbitrary dimensioned array, X, and return X[,,,1]/X[,,,2], etc. I know how to do this by turning X into a vector, then doing the division, then re-shaping as an array, but that doesn't seem very elegant. What I think I am missing is how to paste/substitute/eval a bunch of commas into an array selection. Thanks, --Mike -- Mike Meyer, Seattle WA
How to manipulate an abitrary dimensioned array.
9 messages · Bert Gunter, Michael M. Meyer, Srinivas Iyyer +3 more
Why doesn't apply() already do what you want? -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mike Meyer Sent: Thursday, October 27, 2005 2:50 PM To: r-help at stat.math.ethz.ch Subject: [R] How to manipulate an abitrary dimensioned array. If I have an n1 x n1 x 2 array X I can calculate, say, X[,,1]/X[,,2]. If it is a 4 dimensional array then I want to be able to calculate X[,,,1]/X[,,,2], and similarly for higher dimensions. How can I write a function to do this in a general way without having to do a switch for each possible length(dim(X)). So I want a function g that will take an arbitrary dimensioned array, X, and return X[,,,1]/X[,,,2], etc. I know how to do this by turning X into a vector, then doing the division, then re-shaping as an array, but that doesn't seem very elegant. What I think I am missing is how to paste/substitute/eval a bunch of commas into an array selection. Thanks, --Mike -- Mike Meyer, Seattle WA
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Thanks for the suggestion. Perhaps I can see how to use apply to get the ratio, but say I also want to return X[,,,,1] in a general way. Maybe I am being dense but I just don't see it --- probably as a result of too much Perl/Python/Java recently that is clouding my mind. So can someone suggest a general function that will give me the last layer of an arbitrary dimensioned array?
Berton Gunter wrote:
Why doesn't apply() already do what you want? -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mike Meyer Sent: Thursday, October 27, 2005 2:50 PM To: r-help at stat.math.ethz.ch Subject: [R] How to manipulate an abitrary dimensioned array. If I have an n1 x n1 x 2 array X I can calculate, say, X[,,1]/X[,,2]. If it is a 4 dimensional array then I want to be able to calculate X[,,,1]/X[,,,2], and similarly for higher dimensions. How can I write a function to do this in a general way without having to do a switch for each possible length(dim(X)). So I want a function g that will take an arbitrary dimensioned array, X, and return X[,,,1]/X[,,,2], etc. I know how to do this by turning X into a vector, then doing the division, then re-shaping as an array, but that doesn't seem very elegant. What I think I am missing is how to paste/substitute/eval a bunch of commas into an array selection. Thanks, --Mike -- Mike Meyer, Seattle WA
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Mike Meyer, Seattle WA
Dear group, I have a matrix with readings for ~180 variables observed in 240 conditions. I am doing a hierarchical clustering method (hclust) by calculating eucledian distances among them. When I plot the dendrogram from hclust, all my variables at the end of the branches are cluttered. I cannot read them properly. I tried using :
x11(width = 100, height = 70, pointsize = 10) plot(mydat.hcluster)
and also by
x11(width = 1000, height = 300, pointsize = 10) plot(mydat.hcluster)
I could not make the dendrogram branches go wide and make variables at the end of braches more legible. Can any one please help me to make a good diagram so that I can see the lables at the end of branches more clearly. Thank you. cheers Sri
Not sure what you're after, but the kth dimension of an array y can be obtained as: apply(y,k,c). Each column of the resulting matrix can then be dimensioned, if you like, via dim(y)[-k] . -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box
-----Original Message----- From: Mike Meyer [mailto:mikem at salter-point.com] Sent: Thursday, October 27, 2005 3:43 PM To: Berton Gunter Cc: r-help at stat.math.ethz.ch Subject: Re: [R] How to manipulate an abitrary dimensioned array. Thanks for the suggestion. Perhaps I can see how to use apply to get the ratio, but say I also want to return X[,,,,1] in a general way. Maybe I am being dense but I just don't see it --- probably as a result of too much Perl/Python/Java recently that is clouding my mind. So can someone suggest a general function that will give me the last layer of an arbitrary dimensioned array? Berton Gunter wrote:
Why doesn't apply() already do what you want? -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the
scientific learning
process." - George E. P. Box
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mike Meyer Sent: Thursday, October 27, 2005 2:50 PM To: r-help at stat.math.ethz.ch Subject: [R] How to manipulate an abitrary dimensioned array. If I have an n1 x n1 x 2 array X I can calculate, say, X[,,1]/X[,,2]. If it is a 4 dimensional array then I want to be able to calculate X[,,,1]/X[,,,2], and similarly for higher dimensions. How can I write a function to do this in a general way without having to do a switch for each possible length(dim(X)). So I want a
function g
that will take an arbitrary dimensioned array, X, and return X[,,,1]/X[,,,2], etc. I know how to do this by turning X into a vector, then doing the division, then re-shaping as an array, but that doesn't seem very elegant. What I think I am missing is how to paste/substitute/eval a
bunch of
commas into an array selection. Thanks, --Mike -- Mike Meyer, Seattle WA
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html -- Mike Meyer, Seattle WA
On Thu, 27 Oct 2005 16:08:48 -0700 (PDT)
Srinivas Iyyer <srini_iyyer_bio at yahoo.com> wrote:
Dear group, I have a matrix with readings for ~180 variables observed in 240 conditions. I am doing a hierarchical clustering method (hclust) by calculating eucledian distances among them. When I plot the dendrogram from hclust, all my variables at the end of the branches are cluttered. I cannot read them properly. I tried using :
x11(width = 100, height = 70, pointsize = 10) plot(mydat.hcluster)
and also by
x11(width = 1000, height = 300, pointsize = 10) plot(mydat.hcluster)
I could not make the dendrogram branches go wide and make variables at the end of braches more legible. Can any one please help me to make a good diagram so that I can see the lables at the end of branches more clearly. Thank you. cheers Sri
I don't know if it'll help, but I've grown fond of postscript graphs. For example...
postscript("mydendogram.ps", height=800, width=2000, pointsize=[????])
plot(mydendogram)
dev.off()
gives me very clear print, and then the ps2pdf app can turn it into a pdf for e-mailing or import to a presentation. jon b
I feel a bit timid in asking this question: Why create the PS? Why not create the pdf directly? ?pdf You have lots of control over the size and other characteristics, and the pdf can be used by MiKTeX to create a TeX -> pdf document containing your graphic. I'm running R 2.2.0 on a DELL WinXP machine. Charles Annis, P.E. Charles.Annis at StatisticalEngineering.com phone: 561-352-9699 eFax: 614-455-3265 http://www.StatisticalEngineering.com -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of jon butchar Sent: Thursday, October 27, 2005 8:02 PM To: Srinivas Iyyer Cc: r-help at stat.math.ethz.ch Subject: Re: [R] How to make labels on my dendrogam look more clear and visible On Thu, 27 Oct 2005 16:08:48 -0700 (PDT)
Srinivas Iyyer <srini_iyyer_bio at yahoo.com> wrote:
Dear group, I have a matrix with readings for ~180 variables observed in 240 conditions. I am doing a hierarchical clustering method (hclust) by calculating eucledian distances among them. When I plot the dendrogram from hclust, all my variables at the end of the branches are cluttered. I cannot read them properly. I tried using :
x11(width = 100, height = 70, pointsize = 10) plot(mydat.hcluster)
and also by
x11(width = 1000, height = 300, pointsize = 10) plot(mydat.hcluster)
I could not make the dendrogram branches go wide and make variables at the end of braches more legible. Can any one please help me to make a good diagram so that I can see the lables at the end of branches more clearly. Thank you. cheers Sri
I don't know if it'll help, but I've grown fond of postscript graphs. For example...
postscript("mydendogram.ps", height=800, width=2000, pointsize=[????])
plot(mydendogram)
dev.off()
gives me very clear print, and then the ps2pdf app can turn it into a pdf for e-mailing or import to a presentation. jon b ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Mike Meyer <mikem at salter-point.com> writes:
Thanks for the suggestion. Perhaps I can see how to use apply to get the ratio, but say I also want to return X[,,,,1] in a general way. Maybe I am being dense but I just don't see it --- probably as a result of too much Perl/Python/Java recently that is clouding my mind.
I think Berton was hinting at apply(X,5,"[",1) (it does get trickier if you need X[,,2,,,1] or X[,,3:4,,,1:2] because dimensions tend to get lost on the way into and out of the apply FUN argument.) In general, you can use do.call constructs, with TRUE for the missing arguments (there seems to be no nice way to pass missing to do.call).
So can someone suggest a general function that will give me the last layer of an arbitrary dimensioned array? Berton Gunter wrote:
Why doesn't apply() already do what you want? -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mike Meyer Sent: Thursday, October 27, 2005 2:50 PM To: r-help at stat.math.ethz.ch Subject: [R] How to manipulate an abitrary dimensioned array. If I have an n1 x n1 x 2 array X I can calculate, say, X[,,1]/X[,,2]. If it is a 4 dimensional array then I want to be able to calculate X[,,,1]/X[,,,2], and similarly for higher dimensions. How can I write a function to do this in a general way without having to do a switch for each possible length(dim(X)). So I want a function g that will take an arbitrary dimensioned array, X, and return X[,,,1]/X[,,,2], etc. I know how to do this by turning X into a vector, then doing the division, then re-shaping as an array, but that doesn't seem very elegant. What I think I am missing is how to paste/substitute/eval a bunch of commas into an array selection. Thanks, --Mike -- Mike Meyer, Seattle WA
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
-- Mike Meyer, Seattle WA
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
On Thu, 27 Oct 2005 23:19:36 -0400
"Charles Annis, P.E." <AnnisC at ASME.org> wrote:
I feel a bit timid in asking this question: Why create the PS? Why not create the pdf directly? ?pdf You have lots of control over the size and other characteristics, and the pdf can be used by MiKTeX to create a TeX -> pdf document containing your graphic. I'm running R 2.2.0 on a DELL WinXP machine. Charles Annis, P.E. Charles.Annis at StatisticalEngineering.com phone: 561-352-9699 eFax: 614-455-3265 http://www.StatisticalEngineering.com
I'm even more timid in answering... I like to have .ps as my working files and .pdf as the finished(?) ones. I'm using pdflatex (TeTeX) here, so yes it's definitely an extra step. This way though, I can instantly see which files are part of a paper / presentation and (later, if needed) backtrack through the drafts to see why I chose those ones. jon b