[R] CONFUSSING WITH select[!miss] <- 1:sum(!miss)
Rui Barradas
ruipbarradas at sapo.pt
Tue Dec 6 20:04:01 CET 2016
Hello,
The first command line produces a logical vector with TRUE if at least
one row element of ph is NA and FALSE otherwise.
The second creates a vector of zeros with length equal to nrow(ph).
Now the third command line. ! negates miss, so TRUE becomes FALSE and
vice-versa. sum(!miss) counts how many not misses are there and
1:sum(!miss) creates a vector 1, 2, ..., sum(!miss). To see this print
each of these components one by one:
print(miss)
print(!miss)
print(sum(!miss))
etc
And select[!miss] uses a logical index into 'select' to set only the
values of 'select' where !miss is TRUE equal to 1, 2, 3, ...
I believe you should read R-intro.pdf that comes with your installation
of R more carefully, specially sections 2.4 and 2.7.
Hope this helps,
Rui Barradas
Em 06-12-2016 18:18, greg holly escreveu:
> Dear All;
>
> I am very new in R and try to understand the logic for a program has been
> run sucessfully. Here select[!miss] <- 1:sum(!miss) par is confussing me. I
> need to understandand the logic behind this commend line.
>
> Thanks in advance for your help,
>
> Greg
>
>
> miss <- apply(is.na(ph[,c("M1","X1","X2","X3")]),1, any)
> select <- integer(nrow(ph))
> select[!miss] <- 1:sum(!miss)
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list