[R] "untable" function

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Feb 26 13:14:48 CET 2001


> From: RINNER Heinrich <H.RINNER at TIROL.GV.AT>
> To: "'r-help at stat.math.ethz.ch'" <r-help at 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 at 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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list