Question about which() with matrices to delete certain stuff

#1
Let's say I have a {100 x 100} matrix (call it "A") and there's 5 Inf in them. My goal is to replace them with NAs.

I can go which(A==Inf) and this might give me something like [1] 4747 4788 ... 5926. How can I use _this_ data to replace the Inf with NAs?

If course I can use which() with sapply(), and iterate over every column of A and get rid of them in 1 line, but that's quite tedious really. I'm looking for something like A[which(A==Inf) ??? ] to replace them.

Example you guys can refer to:
Code:
A=data.frame(a=c(1,2,3,4,2,1,2,4),b=c(1,2,3,Inf,5,2,4,1))
which(A==Inf)
 

Dason

Ambassador to the humans
#2
Code:
A[as.matrix(A == Inf)] <- NA
Note that you said you had a matrix but you really have a dataframe - there is a difference so you should be careful with your terminology.