[EpiData-list] Epidata XML to R: how to handle labels? - and missing values

epidata-list at lists.umanitoba.ca epidata-list at lists.umanitoba.ca
Mon Jun 13 07:11:36 CDT 2011

I think the answer lies in this:

Which by the way is a very good source for solutions in R.

Partial cut from that is:

To understand value labels in *R*, you need to understand the data 
structure factor <http://www.statmethods.net/input/datatypes.html>.

You can use the factor function to create your own value lables.

|# variable v1 is coded 1, 2 or 3
# we want to attach value labels 1=red, 2=blue, 3=green

mydata$v1 <- factor(mydata$v1,
levels = c(1,2,3),
labels = c("red", "blue", "green"))

|So I think the answer to use factor principles in R.

What might have to be handled differently are floats, which seldom would 
be needed (but can).


One alternative to use the xml directly would be to export to Stata 
format with Manager and then use in R
|# input Stata file
mydata <- read.dta("c:/mydata.dta") |

Regarding Missing values:
What I would do is to compare the direct (simplest) way with the XML 
with the "import" from Stata and then test the behaviour of missing 
values. But do  be aware that currently there are some problems with 
import/export in Manager to and from Stata format with missing values.

Stata has many missing values (.a to .z) and most likely the import to R 
from a Stata file have solved that.

Jens Lauritsen
EpiData Association

More information about the EpiData-list mailing list