Convert Frequencies to Percentages in gmisc transition diagrams

35 Views Asked by At

I am using the gmisc package to make plots like the following one.Transition Diagrams

The gmisc package provides the function getTransitions transitions$getTransitionSet(1)

that returns a table with the transitions. For example

      7 87 94 130 185 188 192 199
  6   1  0  0   0   0   0   0   0
  79  0  0  1   0   0   0   0   0
  87  0  1  0   0   0   0   0   0
  130 0  0  0   3   0   0   0   0
  185 0  0  0   0   1   0   0   0

The numbers in the table now contain the frequency that something happened. For example from state 130 3 times it has moved to state 130. I would like to change those numbers into percentages.

I am not sure what is the best way that will respect the dplyr tables. What I see with str is that

str(transitions$getTransitionSet(1))
 'table' int [1:8, 1:8] 1 0 0 0 0 0 0 0 0 0 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:8] "6" "79" "87" "130" ...
  ..$ : chr [1:8] "7" "87" "94" "130" ...

Is there a nice way that per row will find out the percentage of each value?

Thanks in advance Alex

0

There are 0 best solutions below