[R] Re : Problem with a Matrix

Pascal Oettli kridox at ymail.com
Thu Mar 8 10:46:34 CET 2012

Hi Hamada,

Could the following be helpful?

"dtf" is your data.frame 

nr <- nrow(dtf)
new.dtf <- data.frame(Site.No=seq(1,nr/2))
new.dtf$XXX <- dtf[seq(1,nr,2),3]
new.dtf$YYY <- dtf[seq(2,nr,2),3]


new.mat <- numeric()
new.mat <- cbind(new.mat,dtf[seq(1,nr,2),3])
new.mat <- cbind(new.mat,dtf[seq(2,nr,2),3])


----- Mail original -----
De : Hamada Elsayed Ali <medo_botany at hotmail.com>
À : r-help at r-project.org
Cc : 
Envoyé le : Jeudi 8 mars 2012 18h20
Objet : [R] Problem with a Matrix

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

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,

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