Tuesday, 15 March 2011

vector index function R -



vector index function R -

i trying write function in r looks @ elements of a list , determines whether or not value has changed it's previous state. list

2 2 3 2 5

the function homecoming p-1 boolean vector

true false false false

myy code/pseudo code far this:

did.change<-function(lst){ final.vect=vector() compare=lst (item in lst){ if (we on first item){ next } else if (i==previous i){ final.vect=c(final.vect, false) } else{ final.vect=c(final.vect, true) } } return(final.vect) }

is there function track index of list? way if(index(lst)==1) first statement

as noted in comment,

head(x,-1) == tail(x,-1)

is need. more verbose version be:

x[1:(length(x)-1)] == x[2:length(x]

r

No comments:

Post a Comment