Replace -Inf in dataframe with NA in R [duplicate]
Asked Answered
D

1

5

I have a problem in my dataframe.

https://gofile.io/?c=eNeEAL

I have several values with -Inf entries. When I want to use the cor-function, I always get NA because of that. So I want to replace the -Inf with NA before I use the cor-function, but I cant find a way to replace them successfully.

I tried

dat[mapply(is.infinite, dat)] <- NA

but it did not work.

Any ideas how to solve this?

Dexterdexterity answered 8/5, 2019 at 12:51 Comment(1)
Do not use external files. Cut your file down to a small size and include it in the question itself.Mandi
D
15

We need to do

dat[] <- Map(function(x) replace(x, is.infinite(x), NA), dat)

Or with lapply

dat[sapply(dat, is.infinite)] <- NA
Disney answered 8/5, 2019 at 12:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.