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?

Essi
  • 761
  • 3
  • 12
  • 22

1 Answers1

14

We need to do

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

Or with lapply

dat[sapply(dat, is.infinite)] <- NA
akrun
  • 874,273
  • 37
  • 540
  • 662