Suppose I have a list of logicals, such as returned by lapply:
Theoph$Dose[1] <- NA
Theoph$Time[2] <- NA
Theoph$conc[3] <- NA
lapply(Theoph,is.na)
Is there a direct way to execute logical "or" across all vectors? The
following gives the desired result, but seems unnecessarily complex.
as.logical(apply(do.call("rbind",lapply(Theoph,is.na)),2,"sum"))
Regards,
Tim
Tim Bergsma wrote:> Suppose I have a list of logicals, such as returned by lapply: > > Theoph$Dose[1] <- NA > Theoph$Time[2] <- NA > Theoph$conc[3] <- NA > lapply(Theoph,is.na) > > Is there a direct way to execute logical "or" across all vectors? The > following gives the desired result, but seems unnecessarily complex. > > as.logical(apply(do.call("rbind",lapply(Theoph,is.na)),2,"sum"))Is this what you want? apply(is.na(Theoph), 1, any)> Regards, > > Tim > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > 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.-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
a little simplier:
apply(do.call("rbind",lapply(Theoph,is.na)),2,any)
or
!complete.cases(Theoph)
On 6/8/07, Tim Bergsma <timb@metrumrg.com> wrote:>
> Suppose I have a list of logicals, such as returned by lapply:
>
> Theoph$Dose[1] <- NA
> Theoph$Time[2] <- NA
> Theoph$conc[3] <- NA
> lapply(Theoph,is.na)
>
> Is there a direct way to execute logical "or" across all vectors?
The
> following gives the desired result, but seems unnecessarily complex.
>
>
as.logical(apply(do.call("rbind",lapply(Theoph,is.na)),2,"sum"))
>
> Regards,
>
> Tim
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
[[alternative HTML version deleted]]
Tim Bergsma said the following on 6/8/2007 5:57 AM:> Suppose I have a list of logicals, such as returned by lapply: > > Theoph$Dose[1] <- NA > Theoph$Time[2] <- NA > Theoph$conc[3] <- NA > lapply(Theoph,is.na) > > Is there a direct way to execute logical "or" across all vectors? The > following gives the desired result, but seems unnecessarily complex. > > as.logical(apply(do.call("rbind",lapply(Theoph,is.na)),2,"sum")) > > Regards, > > Tim > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > 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.How about: apply(sapply(Theoph, is.na), 1, any) HTH, --sundar
try the following:
as.logical(rowSums(is.na(Theoph)))
## or
!complete.cases(Theoph)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Tim Bergsma" <timb at metrumrg.com>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, June 08, 2007 2:57 PM
Subject: [R] logical 'or' on list of vectors
> Suppose I have a list of logicals, such as returned by lapply:
>
> Theoph$Dose[1] <- NA
> Theoph$Time[2] <- NA
> Theoph$conc[3] <- NA
> lapply(Theoph,is.na)
>
> Is there a direct way to execute logical "or" across all vectors?
> The
> following gives the desired result, but seems unnecessarily complex.
>
>
as.logical(apply(do.call("rbind",lapply(Theoph,is.na)),2,"sum"))
>
> Regards,
>
> Tim
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> 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.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm