[EpiData-list] Reading the new XML files into R

epidata-list at lists.umanitoba.ca epidata-list at lists.umanitoba.ca
Sat Jun 11 10:34:38 CDT 2011


On Sat, Jun 11, 2011 at 04:44:19PM +0200, epidata-list at lists.umanitoba.ca wrote:
> David,
> 
> Many thanks for this, I have imported my tiny sample file, but don't seem
> able to do anything with it, is this related to you saying you haven't
> started working with value labels.
> 
> Here is some output from R
> 
>  x <- read.epidata.xml("test.epx", dec.sep = ".")> x$datafile_id_0
>         Date   Species Count st
> 1 2009-11-23 Blackbird    34  0
> 2 2010-11-23    Thrush    57  0
> 3 2011-12-24 Blackbird   130  0
> 4 2006-11-23 Blackbird   134  0
> 5 2011-06-23    Thrush    34  0
> 6 2005-05-23   Sparrow    24  0
> > summary(x)              Length Class      Mode
> datafile_id_0 4      data.frame list> boxplot(x$Count)Error in
> plot.window(xlim = xlim, ylim = ylim, log = log, yaxs = pars$yaxs) :
>   need finite 'ylim' valuesIn addition: Warning messages:1: In
> is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'2: In
> is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'3: In
> is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'4: In
> min(x) : no non-missing arguments to min; returning Inf5: In max(x) :
> no non-missing arguments to max; returning -Inf
> 
> 
> I'm also not sure what the st column is.
> 
> You will gather I am right on the edge of my undertstanding of R here.
> 
> 
> Graham
> 

Graham,

read.epidata.xml() returns a list of dataframes. To use other R functions like summary() you just need to get/use the dataframe from the list using double square brackets to extract an element from a list, i.e. [[]]. There is only one dataframe in the list, so it will be the first one, so we use [[1]]:

x <- read.epidata.xml("test.epx", dec.sep = ".")[[1]] 
x
summary(x)
table(x$Species)
barplot(table(x$Species))
etc.

BTW, the field st comes from epidata, I don't know what it is for, I haven't checked the docs yet.

David
--


More information about the EpiData-list mailing list