# [R] comparing 3 datasets

Deepayan Sarkar deepayansarkar at yahoo.com
Wed Jun 20 02:56:31 CEST 2001

```--- pauljohn at ukans.edu wrote:
> I have 3 datasets with the same variables.  I want
> to find out what
> differences there are between the three, to know if
> an experimental
> condition has an effect.  So I decided first to make
> histograms.  So I
> created this handy "histomatic" function that
> creates a picture with the
> 3 histograms on a single image:
>
> I thought I was being clever, but in the end, no!
>
> #read in 3 tables worth
>
>
>
>
> #here's my magical function
> histomatic <- function (s1,s2,s3,var){
>   if (is.numeric (s2[[var]])) {
>   par(mfrow=c(3,1));
>   hist(s1[[var]],breaks=40,xlab=var);
>
>   hist(s2[[var]], breaks=40,xlab=var);
>   hist(s3[[var]], breaks=40,xlab=var);
>   }
> }
> #cycle through all the variables, just grab names
> from first set.
> nameList<-names(RandMastMod0);
> for (var in nameList)
> histomatic(NoFlagMod0,RandMastMod0,NoMastMod0,var)
>
> I knew I wanted a pretty fine grained display, so I
> set breaks at 40.
> Other than that, I don't know for sure what else I
> want.
>
> Here's the problem:
> The histograms shown do not have the same ranges.
> SInce the datasets
> are slightly different, the ranges displayed are
> different, so they are
> difficult to compare visually.  Is there a solution?

An xlim argument should set the same limits for all
the

histomatic <- function (s1,s2,s3,var){
if (is.numeric (s2[[var]])) {
par(mfrow=c(3,1));
xlim <- range(s1[[var]], s2[[var]], s3[[var]]);
hist(s1[[var]], breaks=40,xlab=var, xlim = xlim);
hist(s2[[var]], breaks=40,xlab=var, xlim = xlim);
hist(s3[[var]], breaks=40,xlab=var, xlim = xlim);
}

This should work.

(You might also consider using the lattice (package in
Devel section) function histogram().)

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```