[R] warnings messages from R when returning nothing

Duncan Murdoch murdoch at stats.uwo.ca
Sat Jun 3 21:01:27 CEST 2006

On 6/3/2006 2:44 PM, markleeds at verizon.net wrote:
> Hi : I have old Splus code that I am trying to turn into R
> ( I am using windows Xp and R 2.20 ) and I am getting a warning 
> from one of my statements because the behavior of R is different from Splus.
> below, tempdata is a matrix of numbers and 
> I have the following command which basically runs through the columns and returns the minimum index of the column
> where an NA occurs.
> badindices<-sapply(tempdata,function(x)min(bdind<-seq(along=x)[is.na(x)])))
> The problems seems to be that, if the column doesn't have any NAs,
> then I get the following warning : "no finite arguments to min :
> returning inf". So, consequently, I get a lot of warnings
> anfd -infs.
> I dont have Splus right now but from the code I have under
> the above command it looks like Splus returned NA rather than -inf and didn't give any warnings.  This would be the the way
> I would prefer it to be handled. So, I was
> hoping that there is there a way to avoid getting these 
> warning and get the behavior that Splus gave me by modifying
> the code or setting something in the environment ?

There are no options to get Splus behaviour here, but
I think you'll get what you want with this code:


I'm not sure why you're creating the bdind variable; you could get the 
same thing in badindices without that side effect with the simpler

badindices<-sapply(tempdata,function(x) which(is.na(x))[1])

Duncan Murdoch

More information about the R-help mailing list