[R] disaggregating table

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Oct 23 09:06:55 CEST 2006


On Sun, 22 Oct 2006, Jeff Miller wrote:

> Hi all,
>
> This should be easy, but I can't seem to figure it out.

ind <- rep(1:nrow(newtable), times=newtable$Cnts)
newtable[ind, -5]

gives

     a1 a2 a3 a4 Score
1    1  1  0  0  3.28
1.1  1  1  0  0  3.28
1.2  1  1  0  0  3.28
1.3  1  1  0  0  3.28
2    1  0  1  1  2.63
2.1  1  0  1  1  2.63

Note the row names: data frames must have unique row names.

> I have a table like this named newtable
>
> a1   a2   a3   a4  Cnts     Score
> 1     1    0    0     4      3.28
> 1     0    1    1     2      2.63
>
> I want the following:
>
> a1   a2   a3   a4  Cnts     Score
> 1     1    0    0     4      3.28
> 1     1    0    0     4      3.28
> 1     1    0    0     4      3.28
> 1     1    0    0     4      3.28
> 1     0    1    1     2      2.63
> 1     0    1    1     2      2.63
>
> Actually, the Cnts column could be removed, but it doesn't matter if it
> stays.
>
> Anyone know how to disaggregate with Cnts as the index?
>
> 	[[alternative HTML version deleted]]

Please use properly formatted plain text, as we do ask in the posting 
guide.  I've had to reformat the double-spaced text provided before 
pasting the table.

> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list