Re: [R] "untable" function

About this list Date view Thread view Subject view Author view

From: Prof Brian Ripley (ripley@stats.ox.ac.uk)
Date: Mon 26 Feb 2001 - 22:14:48 EST


Message-Id: <200102261214.MAA11799@toucan.stats.ox.ac.uk>


> From: RINNER Heinrich <H.RINNER@TIROL.GV.AT>
> To: "'r-help@stat.math.ethz.ch'" <r-help@stat.math.ethz.ch>
> Subject: [R] "untable" function
> Date: Mon, 26 Feb 2001 12:38:37 +0100
>
> Dear R-users!
>
> I am using R1.2.0 under Windows NT4.0, and have data of the following form:
>
> > #simple example of data structure:
> > x <- data.frame(group=LETTERS[1:3], class1=1:3, class2=4:6)
> > x
> group class1 class2
> 1 A 1 4
> 2 B 2 5
> 3 C 3 6
>
> I would like to convert this to a data.frame y of the following form:
> > y
> group class counts
> 1 A class1 1
> 2 A class2 4
> 3 B class1 2
> 4 B class2 5
> 5 C class1 3
> 6 C class2 6
>
> So what I'm looking for is something like an "untable"-function. Is there a
> simple "natural" way for this in R, or will I have to loop through rows and
> columns somehow (my "real world" data set consists of 279 rows/groups and
> 100 columns/classes)?

Look in the R-data manual, at functions stack and reshapeLong

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2b30 : Fri 22 Jun 2001 - 18:58:33 EST