Skip to content
Prev 19910 / 398500 Next

Struchture change of a data frame

Beat Huggler wrote:
If your problem is that simple, you can do the following: starting from
a matrix
R> my.matrix
       good bad worse
Blue      1   2     2
Yellow    2   1     3
Black     3   4     4

You can simply say:
R> as.data.frame(as.table(my.matrix))
    Var1  Var2 Freq
1   Blue  good    1
2 Yellow  good    2
3  Black  good    3
4   Blue   bad    2
5 Yellow   bad    1
6  Black   bad    4
7   Blue worse    2
8 Yellow worse    3
9  Black worse    4

If your problem is more complex, then use reshape() as Thomas suggested.
Best,
Z
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._