Re: [R] Need help on changing a table

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Sat, 1 Dec 2007 15:36:17 -0500 (EST)


That's no table that's a data.frame :).

For what you want probably the easiest way is aggregate. Type ?aggregate for the help information

Based on your example and assuming the data is called "mydata" this shold do what you want.

aggregate(mydata[,2:3], by=list(item=mydata$Item), sum)

>
> 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



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 - 20:40:14 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 - 21:30:17 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.