3

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
  • 649
  • 3
  • 10
  • 20

1 Answers1

12

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
  • 789,025
  • 32
  • 460
  • 575