[R] From data.frame to Matrix

Pierre.Ilouga@evotecoai.com Pierre.Ilouga at evotecoai.com
Mon Oct 29 14:36:27 CET 2001


Hi to all.
I'm a relative new R user and I would like someone to help me in solving
the following simple question:
I have a two column (L , T ) data frame. Column L has three levels: a, b ,
and c  and Column T is real valued.

  L          T
  a    0.8
  a   0.9
  a   0.1
  a   -0.8
  a  -1.0
  b  -0.3
  b    0.7
  b       1.0
  b   0.4
  c  -0.5
  c  -1.0

My aim is to get a data frame of the form

      L    T1       T2   T3    T4  T5
     a    0.8   0.9      0.1  -0.8       -1
     b    -0.3      0.7   1.0      0.4   NA
      c   -0.5  -1.0     NA        NA     NA

without using a "for"  loop, but by using functions of the "apply" family
for exemple or something specific to R and more efficient.
How can I solve this problem?
Thanks in advance.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list