[R] Creating a matrix

John Kane jrkrideau at yahoo.ca
Thu Oct 9 16:21:20 CEST 2008


?aggregate ( as Jim Holtman pointed out) is the standard way.  
Another way is to use the reshape package and try something like

 library(reshape)
 names(x)[3] <- "value"
 cast(x, Seller + Art. ~., mean)


(Note the  names(x)[3] <- "value" seems necessary at the moment as reshape only seems to work on a variable named value.  I think this is supposed to change in the near future).


--- On Wed, 10/8/08, SP&BM <sandra_peneda at hotmail.com> wrote:

> From: SP&BM <sandra_peneda at hotmail.com>
> Subject: [R]  Creating a matrix
> To: r-help at r-project.org
> Received: Wednesday, October 8, 2008, 4:03 PM
> Good evening.
> 
> I have this following table and I would like to turn it
> into a matrix in
> which my rows would be filled with de "Sellers",
> my columns with my
> "Articles" and my data would be the mean unitary
> price used by each seller
> in each produt.
> 
>     Seller  Art.     Unit Price
> 1   v1       p1     9.148352
> 2   v2       p1     2.858073
> 3   v3       p1     3.775315
> 4   v4       p1     9.821429
> 5   v3       p1     3.286827
> 6   v5       p2    11.105769
> 
> This is only the head of a table with more than 400.000
> lines, 6.000 sellers
> and 4500 produts.
> Can anybody help me in suh a task considered very difficult
> by someone that
> has heard about R only a few hours?
> 
> Thank you!
> SPBM 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Creating-a-matrix-tp19886510p19886510.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.


      __________________________________________________________________
[[elided Yahoo spam]]



More information about the R-help mailing list