R 3.0.1 OS X Colleagues, If I execute the command: table(OBJECT) the output might look like: 1 2 25 336 I would like it to appear as: 1 25 2 336 I can accomplish this with: TABLE <- table(OBJECT) data.frame(names(TABLE), as.numeric(TABLE)) However, I bet that a more clever approach exists? Any takers? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com
On 06-10-2013, at 19:30, Dennis Fisher <fisher at plessthan.com> wrote:> R 3.0.1 > OS X > > Colleagues, > > If I execute the command: > table(OBJECT) > the output might look like: > 1 2 > 25 336 > > I would like it to appear as: > 1 25 > 2 336 > > I can accomplish this with: > TABLE <- table(OBJECT) > data.frame(names(TABLE), as.numeric(TABLE)) > > However, I bet that a more clever approach exists? Any takers?Have you tried t(table(OBJECT)) ? Berend
If t(table(OBJECT)) does not work, does: u<-as.matrix(table(OBJ)) t(u) -i.e. use matrix operations? On Sun, Oct 6, 2013 at 1:47 PM, LAMONT, ANDREA <LAMONTA@mailbox.sc.edu>wrote:> > > > ________________________________________ > From: r-help-bounces@r-project.orgOn Behalf OfBerend Hasselman > Sent: Sunday, October 06, 2013 1:44:30 PM (UTC-05:00) Eastern Time (US & > Canada) > To: Dennis Fisher > Cc: r-help@stat.math.ethz.ch > Subject: Re: [R] Transposing the output of 'table' > > On 06-10-2013, at 19:30, Dennis Fisher <fisher@plessthan.com> wrote: > > > R 3.0.1 > > OS X > > > > Colleagues, > > > > If I execute the command: > > table(OBJECT) > > the output might look like: > > 1 2 > > 25 336 > > > > I would like it to appear as: > > 1 25 > > 2 336 > > > > I can accomplish this with: > > TABLE <- table(OBJECT) > > data.frame(names(TABLE), as.numeric(TABLE)) > > > > However, I bet that a more clever approach exists? Any takers? > > > Have you tried t(table(OBJECT)) ? > > Berend > > ______________________________________________ > 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. >-- Andrea Lamont, MA Clinical-Community Psychology University of South Carolina Barnwell College Columbia, SC 29208 Please consider the environment before printing this email. CONFIDENTIAL: This transmission is intended for the use of the individual(s) or entity to which it is addressed, and may contain information that is privileged, confidential, and exempt from disclosure under applicable law. Should the reader of this message not be the intended recipient(s), you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy/delete all copies of the original message. [[alternative HTML version deleted]]
On 06-10-2013, at 20:32, Dennis Fisher <fisher at plessthan.com> wrote:> unsuccessful >Please reply to the list and not to me only. That way others can contribute to solving the problem. Berend> Dennis Fisher MD > P < (The "P Less Than" Company) > Phone: 1-866-PLessThan (1-866-753-7784) > Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > > > > On Oct 6, 2013, at 10:44 AM, Berend Hasselman <bhh at xs4all.nl> wrote: > >> >> On 06-10-2013, at 19:30, Dennis Fisher <fisher at plessthan.com> wrote: >> >>> R 3.0.1 >>> OS X >>> >>> Colleagues, >>> >>> If I execute the command: >>> table(OBJECT) >>> the output might look like: >>> 1 2 >>> 25 336 >>> >>> I would like it to appear as: >>> 1 25 >>> 2 336 >>> >>> I can accomplish this with: >>> TABLE <- table(OBJECT) >>> data.frame(names(TABLE), as.numeric(TABLE)) >>> >>> However, I bet that a more clever approach exists? Any takers? >> >> >> Have you tried t(table(OBJECT)) ? >> >> Berend >> >
If you want a dataframe rather than a matrix, I often use the as.data.frame method for table objects. See ?table for the documentation. You can even nicely name the dimensions and frequency. OBJECT <- sample(4, 20, TRUE) as.data.frame(table(var1 = OBJECT), responseName = 'frequency') Jason -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Dennis Fisher Sent: Sunday, October 06, 2013 10:31 AM To: r-help at stat.math.ethz.ch Subject: [R] Transposing the output of 'table' R 3.0.1 OS X Colleagues, If I execute the command: table(OBJECT) the output might look like: 1 2 25 336 I would like it to appear as: 1 25 2 336 I can accomplish this with: TABLE <- table(OBJECT) data.frame(names(TABLE), as.numeric(TABLE)) However, I bet that a more clever approach exists? Any takers? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.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.