[tech-spec] Re: loop return vector

  • From: Henry Carstens <carstens@xxxxxxxxxxxxxxxxxxxxx>
  • To: tech-spec@xxxxxxxxxxxxx
  • Date: Mon, 28 Feb 2005 12:14:46 -0800

# A test fn that takes a vector as input,
# loops through its elements, puts the results of a logical test
# in a new vector and returns the result
simpleReturn<-function(v){

        l<-length(v)

        r<-vector(mode="logical", length=l)

        for (index in 1:l) {

                r[index]<-v[index] > 2
        }

        return(r)

}

v<-c(1:10)

dx<-simpleReturn(v)

dx


Other related posts: