Dear R experts, I am interested in getting the dimensions for the matrix dynamically, based on the the number of elements in a matrix for example. if the number is 12, I should get dim= 3X4, if it is 20, dim=5X4. please help me do this. Thank you Regards karthick -- View this message in context: http://r.789695.n4.nabble.com/R-matrix-help-tp4633372.html Sent from the R help mailing list archive at Nabble.com.
Why would those figues (dim= 3X4, dim=5X4) be the dimensions? Could not they equally be 4X3 an 4X5 or am I completely misunderstanding the question? John Kane Kingston ON Canada> -----Original Message----- > From: karthick.lakshman at gmail.com > Sent: Thu, 14 Jun 2012 05:51:24 -0700 (PDT) > To: r-help at r-project.org > Subject: [R] R matrix help > > Dear R experts, > > I am interested in getting the dimensions for the matrix dynamically, > based > on the the number of elements in a matrix for example. if the number is > 12, > I should get dim= 3X4, if it is 20, dim=5X4. > please help me do this. > > Thank you > Regards > karthick > > -- > View this message in context: > http://r.789695.n4.nabble.com/R-matrix-help-tp4633372.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.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
If you have your data in x, you can try something like matrix(x,length(x)/4,4) hth kd 2012.06.14. 14:51 keltez?ssel, karthicklakshman ?rta:> Dear R experts, > > I am interested in getting the dimensions for the matrix dynamically, based > on the the number of elements in a matrix for example. if the number is 12, > I should get dim= 3X4, if it is 20, dim=5X4. > please help me do this. > > Thank you > Regards > karthick > > -- > View this message in context: http://r.789695.n4.nabble.com/R-matrix-help-tp4633372.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. > >
If the number of elements is 12, the dimensions could be 1x12, 12x1, 2x6, 6x2, 3x4, or 4x3. How did you decide on 3x4? ---------------------------------------------- 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 karthicklakshman > Sent: Thursday, June 14, 2012 7:51 AM > To: r-help at r-project.org > Subject: [R] R matrix help > > Dear R experts, > > I am interested in getting the dimensions for the matrix dynamically, > based > on the the number of elements in a matrix for example. if the number is > 12, > I should get dim= 3X4, if it is 20, dim=5X4. > please help me do this. > > Thank you > Regards > karthick > > -- > View this message in context: http://r.789695.n4.nabble.com/R-matrix- > help-tp4633372.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.
But there are multiple shapes for matrices with 12 elements -- how did you get 3x4 ? You also could have had 1x12, 2x6, 3x4, 4x3, 6x2,12x1 If you have an R object, you can use dim() on it. [Or perhaps slightly more robustly, NCOL() and NROW()] Michael On Thu, Jun 14, 2012 at 7:51 AM, karthicklakshman <karthick.lakshman at gmail.com> wrote:> Dear R experts, > > I am interested in getting the dimensions for the matrix dynamically, based > on the the number of elements in a matrix for example. if the number is 12, > I should get dim= 3X4, ?if it is 20, dim=5X4. > please help me do this. > > Thank you > Regards > karthick > > -- > View this message in context: http://r.789695.n4.nabble.com/R-matrix-help-tp4633372.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.
Can you explain why n=12 should result in 3x4 instead of 2x6 or 6x2 or 4x3 or 1x12 ? On Thu, Jun 14, 2012 at 8:51 AM, karthicklakshman <karthick.lakshman at gmail.com> wrote:> Dear R experts, > > I am interested in getting the dimensions for the matrix dynamically, based > on the the number of elements in a matrix for example. if the number is 12, > I should get dim= 3X4, ?if it is 20, dim=5X4. > please help me do this. > > Thank you > Regards > karthick >-- Sarah Goslee http://www.functionaldiversity.org
What makes you think that with 12 elements the dimensions should be 3x4? It seems that 4x3 would be equally valid. In every use of matrices that I have encountered, the dimensions have been relatable to some known quantity from the problem context, and matrix dimensioning has been an exercise in consistency checking rather than a guessing game. I recommend that you look at your overall problem again. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. karthicklakshman <karthick.lakshman at gmail.com> wrote:>Dear R experts, > >I am interested in getting the dimensions for the matrix dynamically, >based >on the the number of elements in a matrix for example. if the number is >12, >I should get dim= 3X4, if it is 20, dim=5X4. >please help me do this. > >Thank you >Regards >karthick > >-- >View this message in context: >http://r.789695.n4.nabble.com/R-matrix-help-tp4633372.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.
But the meaning of a 3x4 table is rather different than the meaning of a 1x12 table. Regardless, you probably want to start with integer factorization, and can read more about implementations in R here (and elsewhere): http://tolstoy.newcastle.edu.au/R/help/05/01/10007.html Sarah On Thu, Jun 14, 2012 at 11:27 AM, karthick lakshman <karthick.lakshman at gmail.com> wrote:> Hello Sarah, > > I am finally going to plot the matrix something like a rectangular or square > table. so if it is like 3X4 or 4x5 the table would look better. > > Regards. > karthick > > > On Thu, Jun 14, 2012 at 8:42 PM, Sarah Goslee <sarah.goslee at gmail.com> > wrote: >> >> Can you explain why n=12 should result in 3x4 instead of 2x6 or 6x2 or >> 4x3 or 1x12 ? >> >> On Thu, Jun 14, 2012 at 8:51 AM, karthicklakshman >> <karthick.lakshman at gmail.com> wrote: >> > Dear R experts, >> > >> > I am interested in getting the dimensions for the matrix dynamically, >> > based >> > on the the number of elements in a matrix for example. if the number is >> > 12, >> > I should get dim= 3X4, ?if it is 20, dim=5X4. >> > please help me do this. >> > >> > Thank you >> > Regards >> > karthick >> > >>-- Sarah Goslee http://www.functionaldiversity.org