[R] Remove cases with -Inf from a data frame
bgunter@4567 @end|ng |rom gm@||@com
Sat Feb 16 17:29:19 CET 2019
function(x)all(is.finite(x) | is.na(x) )
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sat, Feb 16, 2019 at 8:25 AM Bert Gunter <bgunter.4567 using gmail.com> wrote:
> Many ways. I assume you know that Inf and -Inf are (special) numeric
> values that can be treated like other numerics. i.e.
> > 1 == - Inf
>  FALSE
> So straightforward indexing (selection) would do it.
> But there is also ?is.infinite and ?is.finite, so
> apply(yourdat, 1, function(x)all(is.finite(x)))
> would produce the index vector to keep rows with only finite values
> assuming yourdat contains only numeric data. If this is not the case, just
> select the numeric columns to index on, i.e.
> apply(yourdat[sapply(yourdat,is.numeric)], 1, function(x)
> One possible problem here is handling of NA's:
>  FALSE FALSE
> ... so rows containing NA's but no -Inf's would also get removed. If you
> wish to keep rows with NA's but no -Inf's, then
> function(x)(is.finite(x) | is.na(x) )
> could be used.
> Bert Gunter
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> On Sat, Feb 16, 2019 at 7:07 AM AbouEl-Makarim Aboueissa <
> abouelmakarim1962 using gmail.com> wrote:
>> Dear All: good morning
>> 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
>> with many thanks
>> *AbouEl-Makarim Aboueissa, PhD*
>> *Professor, Statistics and Data Science*
>> *Graduate Coordinator*
>> *Department of Mathematics and Statistics*
>> *University of Southern Maine*
>> [[alternative HTML version deleted]]
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help