[R] Need help on changing a table
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Dec 1 19:21:57 CET 2007
Note that read.table() reads a table and returns a _data frame_. So it is
the _data frame_ that you want to change (a table is something else in R).
This is a simple application of aggregate(), e.g.
> aggregate(z[-1], list(Item=z$Item), sum)
Item X3d_Plot XY_plot
1 1 1 2
2 2 2 1
where I got z from read.table("clipboard", header=TRUE).
On Sat, 1 Dec 2007, gsmkb86 wrote:
>
> Hi all:
> Im kind of new on R and I need help changing a table. The thing is, i read a
> file on R using the read.table command and the table looks like this:
> Item 3d Plot XY plot
> 001 1 0
> 001 0 1
> 001 0 1
> 002 1 0
> 002 1 0
> 002 0 1
> ... .. ..
> And what I want to do is generate a new table by item with the sum of the
> numbres, the next one is an example:
>
> Item 3d Plot XY plot
> 001 1 2
> 002 2 1
> 003 ... ...
>
> Does anyone know how to do this? Thanks in advance, help is greatly
> appreciated
>
--
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