I've been working around with this response (that I think is a remarkable well constructed answer) but rather than a single dataframe I have a list of dataframes. So, I've been trying to do this:
head(K[[1]])
a b c
1981 0.76 0.93 NaN
1982 Inf 0.33 NaN
1983 0.25 Inf NaN
1984 0.77 0.73 Inf
1985 Inf 0.85 Inf
1986 0.63 0.56 NaN
K <- lapply(seq_along(K), function(i) for (j in 1:3) set(K[[i]], which(is.infinite(K[[i]][[j]])), j, NA))
Which basically it's supposed to replace the Inf values in every element of the list K but I only get this result:
str(K)
List of 200
$ : NULL
$ : NULL
$ : NULL
$ : NULL
...
The for
loop inside the function works when isolated but I cannot get a list with the infinite-free dataframes.
Any suggestion? Regards.