[R] CONFUSSING WITH select[!miss] <- 1:sum(!miss)

William Dunlap wdunlap at tibco.com
Tue Dec 6 20:04:52 CET 2016


R is interactive so you can print the intermediate results:
> ph <- data.frame(M1=c(1,NA,3,4,5), X1=1:5, X2=c(1,2,NA,4,5), X3=1:5,
Y=c(11,12,13,14,NA), row.names=paste0("R",1:5))
> ph
   M1 X1 X2 X3  Y
R1  1  1  1  1 11
R2 NA  2  2  2 12
R3  3  3 NA  3 13
R4  4  4  4  4 14
R5  5  5  5  5 NA
> miss <- apply(is.na(ph[,c("M1","X1","X2","X3")]),1, any)
> miss
   R1    R2    R3    R4    R5
FALSE  TRUE  TRUE FALSE FALSE
> select <- integer(nrow(ph))
> select
[1] 0 0 0 0 0
> sum(!miss)
[1] 3
> select[!miss] <- 1:sum(!miss)
> select
[1] 1 0 0 2 3

Then you can look in the Introduction to R document or ask about the steps
that confuse you.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Dec 6, 2016 at 10:18 AM, greg holly <mak.hholly at gmail.com> wrote:

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

	[[alternative HTML version deleted]]



More information about the R-help mailing list