[R] Remove cases with -Inf from a data frame

AbouEl-Makarim Aboueissa @boue|m@k@r|m1962 @end|ng |rom gm@||@com
Sun Feb 17 13:29:52 CET 2019


Dear Rui and All:

thank you very much for your very helpful responses.

with many thanks
abou
______________________


*AbouEl-Makarim Aboueissa, PhD*

*Professor, Statistics and Data Science*
*Graduate Coordinator*

*Department of Mathematics and Statistics*
*University of Southern Maine*



On Sat, Feb 16, 2019 at 11:36 AM Rui Barradas <ruipbarradas using sapo.pt> wrote:

> Hello,
>
> An alternative, same dataset.
>
> df[apply(df, 1, function(x) all(is.finite(x))), ]
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 16:14 de 16/02/2019, Martin Møller Skarbiniks Pedersen escreveu:
> > On Sat, 16 Feb 2019 at 16:07, AbouEl-Makarim Aboueissa <
> > abouelmakarim1962 using gmail.com> wrote:
> >>
> >> I have a log-transformed data frame with some *-Inf* data values.
> >>
> >> *my question: *how to remove all rows with *-Inf* data value from that
> > data
> >> frame?
> >
> >
> > Hi,
> >    Here is a solution which uses apply.
> >
> > First a data-frame as input:
> >
> > set.seed(1)
> > df <- data.frame(w = sample(c(-Inf,1:20), 10),
> >                   x = sample(c(-Inf,1:20), 10),
> >                   y = sample(c(-Inf,1:20), 10),
> >                   z = sample(c(-Inf,1:20), 10))
> >
> > df <- df[-(unlist(apply(df, 2, function(x) which(x == -Inf)))),]
> >
> > Regards
> > Martin
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help using 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