Q:

Methods for applying is.infinite() to a data frame in R

I'm wondering why I can't apply is.infinite() to a data frame in the same way I can apply is.na to a dataframe in R:
data[is.infinite(data)]<-0
Error in is.infinite(data) : 
  default method not implemented for type 'list'

data[is.na(data)] <-0

Produces no error, however, the documentation on is.infinite implies the same behavior as is.na?.
Does anyone know how I can replace inf values?

A:

Here is one method, using lapply and ifelse:
# create data.frame
df <- data.frame(a=1:10, b=letters[1:10], c=rnorm(10))
df$a[c(2,6)] <- Inf
df$c[c(3,9)] <- Inf

# take care of those infs:
df[] <- lapply(df, function(i) if(is.numeric(i)) ifelse(is.infinite(i), 0, i) else i)

The problem I think is the x is.infinite(x) and is.na(x). The help file for ?is.infinite says

x R object to be tested: the default methods handle atomic vectors

while for ?is.na, it says

x an R object to be tested: the default method for is.na handles atomic vectors, lists and pairlists: that for anyNA also handles NULL.

So the default method of is.infinite does not handle lists (data.frames) where are is.na does.

