[R] About warnings for non-matched items

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Fri Mar 6 14:53:22 CET 2009


> I have many files in my directory. I want to transfer each data into
> one which is readable.
> They have so many possibilities, i have collected(manually and 
> visually) all possibilities and represent them as different numbers.
> 
> Rep[grep('context_log',log1$Remain[1:length(log1$Date)]),]<-"2"
> Rep[grep('gs',log1$Remain[1:length(log1$Date)]),]<-"5"
> Rep[grep('ClockApp',log1$Remain[1:length(log1$Date)]),]<-"6"
> Rep[grep('mce',log1$Remain[1:length(log1$Date)]),]<-"7"
> ......
> I manually collect all possibilities contained in all files!!!
> (manually and visually: this process is so time-consuming, can i 
> have better ideal to collect all possibilities by computer rather 
> than by myself?)
> 
> The programs are fine, but each file doesn't match all 
> possibilities, whenever there are non-matched items with above, then
> warning information come ups:
> 31: In max(i) ... : no non-missing arguments to max; returning -Inf
> 32: In max(i) ... : no non-missing arguments to max; returning -Inf
> 33: In max(i) ... : no non-missing arguments to max; returning -Inf
> they returns non-matched items.
> 
> How to vanish those warnings?

The error means that the input you provided to the max function is missing 
or NULL or of length 0.  At a guess, what has happened is that you've 
called grep, which didn't match anything (and so returned integer(0)), 
then used that as an input to max.

To get rid of the warning, check the input to max first.  e.g.

x1 <- c("foo", "bar", "foo")
g1 <- grep("foo", x1)
if(length(g1)) max(g1)

g2 <- grep("baz", x1)
if(length(g2)) max(g1)

Regards,
Richie.

Mathematical Sciences Unit
HSL



------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}




More information about the R-help mailing list