[R] XML: Reading transition matrices into R

stefan.duke at gmail.com stefan.duke at gmail.com
Thu Nov 12 14:33:53 CET 2009


Hello,
from a software I have the following output in xml (see below):
It is a series of matrices, for each age one. I have 3 categories
(might vary in the application), hence, 3x3 matrices where each
element gives the probability of transition from i to j. I would like
read this data into R (preferably in a list, where each list element
is one of the age specific matrices) and - after altering the values
in R - write it back into the file.  I know that there is an xml
package in R with which I have already struggled, but I have to admit
my understanding is too limited. Maybe somebody had a similar problem
or know the code of the top of his or her head.

Any help appreciated.

Thanks and best,
Stefan





<?xml version="1.0" encoding="UTF-8" standalone="no"?><transitionmatrix>
<transition><age>0</age><sex>0</sex><from>1</from><to>1</to><percent>99.99999</percent></transition><transition><age>0</age><sex>0</sex><from>1</from><to>2</to><percent>0.0</percent></transition><transition><age>0</age><sex>0</sex><from>1</from><to>3</to><percent>0.0</percent></transition><transition><age>0</age><sex>0</sex><from>2</from><to>1</to><percent>0.0</percent></transition><transition><age>0</age><sex>0</sex><from>2</from><to>2</to><percent>99.999985</percent></transition><transition><age>0</age><sex>0</sex><from>2</from><to>3</to><percent>0.0</percent></transition><transition><age>0</age><sex>0</sex><from>3</from><to>1</to><percent>0.0</percent></transition><transition><age>0</age><sex>0</sex><from>3</from><to>2</to><percent>0.0</percent></transition><transition><age>0</age><sex>0</sex><from>3</from><to>3</to><percent>99.999985</percent></transition><transition><age>0</age><sex>1</sex><from>1</from><to>1</to><percent>100.0</percent></transition><transition><age>0</age><sex>1</sex><from>1</from><to>2</to><percent>0.0</percent></transition><transition><age>0</age><sex>1</sex><from>1</from><to>3</to><percent>0.0</percent></transition><transition><age>0</age><sex>1</sex><from>2</from><to>1</to><percent>0.0</percent></transition><transition><age>0</age><sex>1</sex><from>2</from><to>2</to><percent>100.0</percent></transition><transition><age>0</age><sex>1</sex><from>2</from><to>3</to><percent>0.0</percent></transition><transition><age>0</age><sex>1</sex><from>3</from><to>1</to><percent>0.0</percent></transition><transition><age>0</age><sex>1</sex><from>3</from><to>2</to><percent>0.0</percent></transition><transition><age>0</age><sex>1</sex><from>3</from><to>3</to><percent>100.0</percent></transition><transition><age>1</age><sex>0</sex><from>1</from><to>1</to><percent>99.99999</percent></transition><transition><age>1</age><sex>0</sex><from>1</from><to>2</to><percent>0.0</percent></transition><transition><age>1</age><sex>0</sex><from>1</from><to>3</to><percent>0.0</percent></transition><transition><age>1</age><sex>0</sex><from>2</from><to>1</to><percent>0.0</percent></transition><transition><age>1</age><sex>0</sex><from>2</from><to>2</to><percent>99.999985</percent></transition><transition><age>1</age><sex>0</sex><from>2</from><to>3</to><percent>0.0</percent></transition><transition><age>1</age><sex>0</sex><from>3</from><to>1</to><percent>0.0</percent></transition><transition><age>1</age><sex>0</sex><from>3</from><to>2</to><percent>0.0</percent></transition><transition><age>1</age><sex>0</sex><from>3</from><to>3</to><percent>99.999985</percent></transition><transition><age>1</age><sex>1</sex><from>1</from><to>1</to><percent>100.0</percent></transition><transition><age>1</age><sex>1</sex><from>1</from><to>2</to><percent>0.0</percent></transition><transition><age>1</age><sex>1</sex><from>1</from><to>3</to><percent>0.0</percent></transition><transition><age>1</age><sex>1</sex><from>2</from><to>1</to><percent>0.0</percent></transition><transition><age>1</age><sex>1</sex><from>2</from><to>2</to><percent>100.0</percent></transition><transition><age>1</age><sex>1</sex><from>2</from><to>3</to><percent>0.0</percent></transition><transition><age>1</age><sex>1</sex><from>3</from><to>1</to><percent>0.0</percent></transition><transition><age>1</age><sex>1</sex><from>3</from><to>2</to><percent>0.0</percent></transition><transition><age>1</age><sex>1</sex><from>3</from><to>3</to><percent>100.0</percent></transition><transition><age>2</age><sex>0</sex><from>1</from><to>1</to><percent>99.35205</percent></transition><transition><age>2</age><sex>0</sex><from>1</from><to>2</to><percent>0.6479474</percent></transition><transition><age>2</age><sex>0</sex><from>1</from><to>3</to><percent>0.0</percent></transition><transition><age>2</age><sex>0</sex><from>2</from><to>1</to><percent>0.0</percent></transition><transition><age>2</age><sex>0</sex><from>2</from><to>2</to><percent>97.101456</percent></transition><transition><age>2</age><sex>0</sex><from>2</from><to>3</to><percent>2.8985496</percent></transition><transition><age>2</age><sex>0</sex><from>3</from><to>1</to><percent>0.0</percent></transition><transition><age>2</age><sex>0</sex><from>3</from><to>2</to><percent>0.0</percent></transition><transition><age>2</age><sex>0</sex><from>3</from><to>3</to><percent>100.0</percent></transition><transition><age>2</age><sex>1</sex><from>1</from><to>1</to><percent>97.82136</percent></transition><transition><age>2</age><sex>1</sex><from>1</from><to>2</to><percent>2.1786473</percent></transition><transition><age>2</age><sex>1</sex><from>1</from><to>3</to><percent>0.0</percent></transition><transition><age>2</age><sex>1</sex><from>2</from><to>1</to><percent>0.0</percent></transition><transition><age>2</age><sex>1</sex><from>2</from><to>2</to><percent>93.33336</percent></transition><transition><age>2</age><sex>1</sex><from>2</from><to>3</to><percent>6.6666408</percent></transition><transition><age>2</age><sex>1</sex><from>3</from><to>1</to><percent>0.0</percent></transition><transition><age>2</age><sex>1</sex><from>3</from><to>2</to><percent>0.0</percent></transition><transition><age>2</age><sex>1</sex><from>3</from><to>3</to><percent>100.0</percent></transition>
</transitionmatrix>




More information about the R-help mailing list