[R] Problem with a Matrix

Petr PIKAL petr.pikal at precheza.cz
Thu Mar 8 11:04:20 CET 2012


Hi

> 
> Dear All,
> 
> I have a problem in making a matrix from a data. I did a summary data 
from a
> big data frame using (ddply), the resulting table is like that:
> 
> Site.No    Plant.Name    Cover.Percentage
> 1                XXX                15
> 1                YYY                 20
> 2                XXX                18
> 2                YYY                 21
> 3                XXX                14
> 3                YYY                 26
> 
> I need to convert it to the following:
> 
>         XXX      YYY
> 1      15        20
> 2      18        21
> 3      14        26

seems to be a work for reshape or cast or maybe xtabs

test <-read.table("clipboard", header=T)
test
  Site.No Plant.Name Cover.Percentage
1       1        XXX               15
2       1        YYY               20
3       2        XXX               18
4       2        YYY               21
5       3        XXX               14
6       3        YYY               26
names(test)<-c("site", "plant", "perc")


> xtabs(perc~site+plant, data=test)
    plant
site XXX YYY
   1  15  20
   2  18  21
   3  14  26 

Regards
Petr




> 
> I tried for the whole day yesterday but I can't solve it. Could you 
please
> help me.
> 
> Thanks in advance for all of you,
> Hamada
> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-
> a-Matrix-tp4455954p4455954.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.



More information about the R-help mailing list