[R] extraction

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Apr 19 16:31:29 CEST 2001


On Thu, 19 Apr 2001, Heberto Ghezzo wrote:

> Hello everybody
> I am trying to extract some observations from a data frame, ie the
> subjects that belong to a given group, and although t-test etc work
> if I try to obtain the number of subjects in the subgroup i get some
> funny numbers. All the subjects with NA for group are included in
> the subgroups 'group==1' etc.
> Is this a bug?

The description of BUGS in the FAQ will help you answer your own question.

> for example in Windoze

???

> R : Copyright 2001, The R Development Core Team
> Version 1.2.2  (2001-02-26)
>
>
> > z1 <- rnorm(100)
> > z2<- rep(1:5,20)
> > z3 <- z2
> > z3[z1>1] <- NA
> > z1[z2==1]
>  [1]  1.16747148  0.58088013  1.00958356  1.35477371 -
> 1.19790468  0.07028495 -0.67707300
>  [8] -0.10999675  1.78765730  0.52044707  0.47965798 -
> 2.05768565  1.16349068 -0.75485570
> [15] -0.70517830  0.86419410 -0.03514043 -0.84861275 -
> 0.50284191  0.64971596
> > z1[z3==1]
>  [1]          NA  0.58088013          NA          NA          NA          NA
>         NA
>  [8] -1.19790468          NA  0.07028495 -0.67707300 -0.10999675
>        NA          NA
> [15]          NA  0.52044707  0.47965798 -2.05768565          NA -
> 0.75485570          NA
> [22] -0.70517830  0.86419410          NA -0.03514043 -0.84861275
>        NA -0.50284191
> [29]          NA          NA          NA  0.64971596
> >
>
> the first with z2==1 gives me the 20 subjects OK but the second
> should have given me less than 20 but it returns 32! it adds all the
> NA's for z3.
> I would have thought that z3==1 excluded all the NA's
> Thanks for any explanation.

NA means unknown. So you don't know if those values are one, and all you
can get is a report that they might be.  I suspect you intended
z1[z3 %in% 1]


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