[R] extraction
Heberto Ghezzo
Heberto at meakins.lan.mcgill.ca
Thu Apr 19 16:12:33 CEST 2001
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?
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.
R. Heberto Ghezzo Ph.D.
Meakins-Christie Labs
McGill University
Montreal - Canada
heberto at meakins.lan.mcgill.ca
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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