| home | help | back | first | fref | pref | prev | next | nref | lref | last | post |
Date: Thu, 12 Aug 1999 08:45:51 -0700 (PDT) From: "Charles E. (Ted) Wright" <cew@aris.ss.uci.edu> To: Steve Bousquin <sbousqu@sfwmd.gov> Cc: "s-news@wubios.wustl.edu" <s-news@wubios.wustl.edu> In-Reply-To: <37B2C40A.DE7240EF@sfwmd.gov> Message-Id: <Pine.SOL.4.05.9908120833370.29116-100000@aris.ss.uci.edu> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII This summary is somewhat misleading. The matrix() call in the suggested summary makes no difference at all: i.e., table(data) will do the same thing as table(matrix(data)). The call to matrix turns the vector into an n x 1 matrix by default, becuase no values have been supplied for the arguments nrow= or ncol=, but that transformation has absolutely no effect on the table call. Because the vector data contains character data and not a category (or factor in older versions of S), the explicitly correct answer would be table(category(data)) or equivalently table(factor(data)) However, because table() examines its arguments and calls category() for those that are not already categorical, the explicit call to category() or factor() is unnecessary and, thus, simply table(data) works fine. Again, however, the matrix() call has no logical or actual advantage here. Ted Wright ============================================================================== | Charles E. (Ted) Wright: Associate Professor | | Interim Department Chair, Cognitive Sciences | | Office: Room 3119 USMail: Dept. of Cognitive Sciences | | Social Science Plaza Social Sciences Plaza, Rm. 3151 | | (949) 824-7589 UC-Irvine | | Fax: (949) 856-2590 Irvine, CA 92697-5100 | | email: cewright@uci.edu web: www.socsi.uci.edu/cogsci | ============================================================================== On Thu, 12 Aug 1999, Steve Bousquin wrote: > > Thanks for the large response. Several people suggested > that this could not be done without a custom function, and a > number of people sent interesting functions. I can > summarize if anyone is interested. However, > > > table(matrix(data)) > > > worked fine for this purpose. > > > > > Steve Bousquin wrote: > > > > Is there an S-Plus function that will count the number of > > unique values or text items in a column, and give the number > > of occurrances of each alongside the value > > or text ? > > > > E.g., for a column that reads: > > > > At > > B > > A > > A > > B > > A > > A > > C > > > > I want output that reads: > > > > A 3 > > At 1 > > B 2 > > C 1 > > > > Thanks! > > > > ======================================= > > Steve Bousquin > > > > Kissimmee River Restoration Division > > South Florida Water Management District > > West Palm Beach, FL > > > > sbousqu@sfwmd.gov > > ======================================= > > ----------------------------------------------------------------------- > > This message was distributed by s-news@wubios.wustl.edu. To unsubscribe > > send e-mail to s-news-request@wubios.wustl.edu with the BODY of the > > message: unsubscribe s-news > > -- > ======================================= > Steve Bousquin > > Kissimmee River Restoration Division > South Florida Water Management District > West Palm Beach, FL > > sbousqu@sfwmd.gov > ======================================= > ----------------------------------------------------------------------- > This message was distributed by s-news@wubios.wustl.edu. To unsubscribe > send e-mail to s-news-request@wubios.wustl.edu with the BODY of the > message: unsubscribe s-news > ----------------------------------------------------------------------- This message was distributed by s-news@wubios.wustl.edu. To unsubscribe send e-mail to s-news-request@wubios.wustl.edu with the BODY of the message: unsubscribe s-news
| home | help | back | first | fref | pref | prev | next | nref | lref | last | post |