[R] R: question about vectors + for loop

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jun 16 15:59:47 CEST 1999


> X-Authentication-Warning: stat.math.ethz.ch: majordom set sender to 
owner-r-help at stat.math.ethz.ch using -f
> Date: Sat, 5 Jun 1999 19:51:57 +0100
> From: Guido Masarotto <guido at hal.stat.unipd.it>
> To: Maria Wolters <wolters at ikp.uni-bonn.de>
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] R: question about vectors + for loop
> 
> On Sat, Jun 05, 1999 at 04:14:11PM +0200, Maria Wolters wrote:
> > a) is there a straightforward way of saying
> >   for all factors f in a data frame {
> >       any old function, e.g. max(f)
> >   }
> 
>   I am not sure to understand completly the question. Anyway, if
>   d is a data.frame, you can extract the factors in d using something
>   like
>   > d.only.factor <- d[,unlist(lapply(d,is.factor))]
>   Then, you can use lapply again to apply a 'old function' to the
>   columns of d.only.factor. However, keep in mind that max, sum and
>   like are considered not meaningful for factor. So, if you really
>   insist in computing the max of the d.only.factor columns 
>   (assuming that this make sense) you should use something like
>   > lapply(d.only.factor, function(x) max(as.numeric(x)))
> 
>   If this sounds cryptic, look to the manual pages (e.g., ?lapply,
>   ?unlist,...) and perhaps to some of the  suggested reading 
>   listed in the FAQ (the recommended one is
>   W. N. Venables and B. D. Ripley (1997), 
>   "Modern Applied Statistics with S-PLUS. Second Edition".
>   Springer, ISBN 0-387-98214-0
>   Third edition is forthcoming (Brian Ripley can be more precise)
>   so my suggestion is to get a copy from a library, not from a book
>   shop) 
>
Due in early August, but the main differences relate to new versions of
S-PLUS. See

http://www.stats.ox.ac.uk/pub/MASS3

for details


> > b) how can you construct a new data frame d' from 
> >    a given data frame d which contains only rows
> >    with [X=="A"] (x is a factor of d)?
> >    I know there's an obvious way, but with 50+ columns,
> >    that's a wee bit tedious :)
> 
>    d.XequaltoA <- d[d$X=="A",]
>    should do the work. Easy, isn't it?
> 
>  
> > c) could it be possible that there's a bug in the implementation of 
> >     the Kolmogorov-Smirnov test? 
> 
>   I suspect that you must try to be more specific (and maybe,
>   fill a bug report (?bug.report))
> 
>   Hoping this can help.
> 
>   guido
> 
> 
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> 
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
Brian D. Ripley,                  ripley at 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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list