[R] Creating a matrix

jim holtman jholtman at gmail.com
Thu Oct 9 04:15:55 CEST 2008


You can read it in as a data.frame and then use 'aggregate' to get the mean:

> x <- read.table(textConnection('   Seller  Art.     Unit_Price
+ 1   v1       p1     9.148352
+ 2   v1       p1     2.858073
+ 3   v1       p2     3.775315
+ 4   v1       p2     9.821429
+ 5   v1       p3     3.286827
+ 6   v1       p3    11.105769') , header=TRUE)
> closeAllConnections()
>
> x
  Seller Art. Unit_Price
1     v1   p1   9.148352
2     v1   p1   2.858073
3     v1   p2   3.775315
4     v1   p2   9.821429
5     v1   p3   3.286827
6     v1   p3  11.105769
> aggregate(x$Unit_Price, list(x$Seller, x$Art.), mean)
  Group.1 Group.2        x
1      v1      p1 6.003213
2      v1      p2 6.798372
3      v1      p3 7.196298
>


On Wed, Oct 8, 2008 at 4:03 PM, SP&BM <sandra_peneda at hotmail.com> wrote:
>
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list