[R] (no subject)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Nov 22 01:10:51 CET 2005


Ravi Varadhan <RVARADHAN at jhmi.edu> writes:

> Hi,
> 
> I have written the following function to check whether a vector has elements
> satisfying monotonicity.
> 
> is.monotone <- function(vec, increase=T){
> # check for monotonicity in time-stamp data for cortisol collection
> ans <- TRUE
> vec.nomis <- vec[!is.na(vec)]
> if (increase & any(diff(vec.nomis,1) < 0, na.rm=T)) ans <- FALSE
> if (!increase & any(diff(vec.nomis,1) > 0, na.rm=T)) ans <- FALSE
> ans
> }
> 
> This works correctly, but I get this error message as below.
> 
> > x <- 2:10
> > is.monotone(x)
> [1] TRUE
> Warning messages:
> 1: the condition has length > 1 and only the first element will be used in:
> if (increase & any(diff(vec.nomis, 1) < 0, na.rm = T)) ans <- FALSE 
> 2: the condition has length > 1 and only the first element will be used in:
> if (!increase & any(diff(vec.nomis, 1) > 0, na.rm = T)) ans <- FALSE 
> >
> 
> I am unable to see why the condition should have a length greater than 1,
> since "any" should give me a single logical value.  
> 
> Can any one tell me what is going on here?  ( I am using version 2.1.1 on
> Windows).

Would you happen to have a variable called "T" around?

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list