[R] matrix shifting

Gottfried Gruber ggruber at terminal.at
Thu Mar 16 23:31:30 CET 2006


hi,

somehow i can not figure it it, although it sounds simple. i have a matrix and 
i want one column to be laged (like the lag-operator).
e.g.
mymatrix[,2]=ifelse(mymatrix[,1]<lag(mymatrix[,1],-1),-1,0) #i know this do 
not work just for illustration

as a result i want to have in column 2 a -1 if the current value (in the row) 
is lower than the last value (from the row above) and otherwise zero.
can that be done in one simple command, or do i have to use a loop?

thanks for any comments,
tia gg
-- 
---------------------------------------------------
Gottfried Gruber
mailto:gottfried.gruber at terminal.at
www: http://gogo.sehrsupa.net




More information about the R-help mailing list