From ripley at stats.ox.ac.uk  Fri Mar 14 08:57:11 2003
From: ripley at stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Fri Mar 14 09:57:25 2003
Subject: [Rd] The function 'apply' (PR#2633)
In-Reply-To: <200303132219.h2DMJen9003276@pubhealth.ku.dk>
Message-ID: <Pine.LNX.4.44.0303140849300.2783-100000@gannet.stats>

The `something wrong' is in your reading (or lack of it).  Not checking 
the help page before filing a bug report just wastes the developer's time.
That *is* `a cause for concern': it applies to far too many bug reports.

Let me read the help(apply) page for you:

       X: the array to be used.

Details:

     If `X' is not an array but has a dimension attribute, `apply'
     attempts to coerce it to an array via `as.matrix' if it is
     two-dimensional (e.g. data frames) or via `as.array'.


so test.frame (presumably a data frame) is coerced to a matrix and the 
results are correct.

What I believe you intended can be done by sapply(test.frame, is.factor).

If you do ever find a real bug in R, please supply a reproducible example 
with your report.  You have omitted to tell us what test.frame is.

On Thu, 13 Mar 2003 louisept@pweh.com wrote:

> Full_Name: Paul Louisell
> Version: 1.6.2
> OS: Windows NT
> Submission from: (NULL) (192.249.47.9)
> 
> 
> I've found a problem with either the 'apply' or 'is.factor' functions, and it
> seems like it might be cause for concern. Here are the commands taken directly
> from the R session:
> 
> > is.factor(test.frame[, 1])
> [1] TRUE
> > is.factor(test.frame[, 2])
> [1] TRUE
> > is.factor(test.frame[, 3])
> [1] TRUE
> > is.factor(test.frame[, 4])
> [1] TRUE
> > apply(test.frame, 2, is.factor)
>    X1    X2    X3    X4 
> FALSE FALSE FALSE FALSE 
> 
> 
> All of the variables in test.frame are factors, and is.factor returns TRUE when
> it's used on each factor individually. When it's used inside of apply, all of
> the variables return the value FALSE. So there's something wrong in at least one
> of these functions.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] The function 'apply' (PR#2633)
ripley@stats.ox.ac.uk