Hi there, b is my dataframe. I have a dataframe. I am trying to get rid of the -INF values but didnt have much luck b[which(is.finite(b))] I can get rid of it for a single column b[,1][which(is.finite(b[,2]))] but not for all dataframe I used it inside of a sapply but still no dice my guess is it might have some differing row numbers and just ignoring the columns itself. Thanks Ramya -- View this message in context: http://r.789695.n4.nabble.com/Removing-Inf-values-from-all-the-colums-in-a-dataframe-tp3322059p3322059.html Sent from the R help mailing list archive at Nabble.com.
Peter Ehlers
2011-Feb-24 11:46 UTC
[R] Removing -Inf values from all the colums in a dataframe
On 2011-02-23 19:27, Ramya wrote:> > Hi there, > > b is my dataframe. > > I have a dataframe. I am trying to get rid of the -INF values but didnt have > much luck > > b[which(is.finite(b))] > > I can get rid of it for a single column > > b[,1][which(is.finite(b[,2]))] but not for all dataframe I used it inside of > a sapply but still no dice > > my guess is it might have some differing row numbers and just ignoring the > columns itself. > > Thanks > RamyaNote that R does not have "-INF" values. I'm not sure that I understand what you mean by 'get rid of'; a reproducible example would help. b <- data.frame(x = 1:5, y = 11:15) b[2, 1] <- b[3, 2] <- -1/0 b Here are a couple of ways to delete all cases that include a -Inf: 1. idx <- apply(b, 1, function(x) all(is.finite(x))) b[idx, ] 2. b[is.finite(rowSums(b)), ] This assumes that all of your variables are numeric; if not, you'll have to subset appropriately but, as I said, a reproducible example would .... Peter Ehlers