Re: [R] Need help on changing a table

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat, 1 Dec 2007 18:21:57 +0000 (GMT)

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 01 Dec 2007 - 18:25:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 01 Dec 2007 - 18:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.