Dewez Thomas
2004-Jul-27 14:44 UTC
[R] computing differences between consecutive vector elements
Dear R-users, I am a newbie to R so please excuse this naive question for which I couldn't seem to find online answers. I have this data frame containing a series of locations through time (x,y,z,t). I would like to compute the difference in x, y and z between t-1 and t. Sounds easy enough, but how on earth does one loop through vector elements and compute this difference? Thanks Thomas *** Le contenu de cet e-mail et de ses pi??ces jointes est destin?? ?? l'usage exclusif du (des) destinataire(s) express??ment d??sign??(s) comme tel(s). En cas de r??ception de cet e-mail par erreur, le signaler ?? son exp??diteur et ne pas en divulguer le contenu. L'absence de virus a ??t?? v??rifi?? ?? l'??mission du message. Il convient n??anmoins de v??rifier l'absence de corruption ?? sa r??ception. The contents of this email and any attachments are confidential. They are intended for the named recipient(s) only. If you have received this email in error please notify the system manager or the sender immediately and do not disclose the contents to anyone or make copies. eSafe scanned this email for viruses, vandals and malicious content. ***
Liaw, Andy
2004-Jul-27 14:50 UTC
[R] computing differences between consecutive vector elements
Not exactly sure what you want, but seems like you can sort the data frame by `t', then do diff() on the x, y, and z columns. Andy> From: Dewez Thomas > > Dear R-users, > > I am a newbie to R so please excuse this naive question for > which I couldn't > seem to find online answers. > > I have this data frame containing a series of locations through time > (x,y,z,t). I would like to compute the difference in x, y and > z between t-1 > and t. > > Sounds easy enough, but how on earth does one loop through > vector elements > and compute this difference? > > Thanks > > Thomas > *** > Le contenu de cet e-mail et de ses pi??ces jointes est destin?? > ?? l'usage exclusif du > (des) destinataire(s) express??ment d??sign??(s) comme tel(s). > En cas de r??ception de cet > e-mail par erreur, le signaler ?? son exp??diteur et ne pas en > divulguer le contenu. > L'absence de virus a ??t?? v??rifi?? ?? l'??mission du message. Il > convient n??anmoins de > v??rifier l'absence de corruption ?? sa r??ception. > > The contents of this email and any attachments are > confidential. They are intended for > the named recipient(s) only. If you have received this email > in error please notify the > system manager or the sender immediately and do not disclose > the contents to > anyone or make copies. eSafe scanned this email for viruses, > vandals and malicious > content. > *** > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
Uwe Ligges
2004-Jul-27 17:55 UTC
[R] computing differences between consecutive vector elements
Dewez Thomas wrote:> Dear R-users, > > I am a newbie to R so please excuse this naive question for which I couldn't > seem to find online answers. > > I have this data frame containing a series of locations through time > (x,y,z,t). I would like to compute the difference in x, y and z between t-1 > and t. > > Sounds easy enough, but how on earth does one loop through vector elements > and compute this difference?See ?diff Hence for a data frame X: lapply(X, diff) Uwe Ligges> Thanks > > Thomas > *** > Le contenu de cet e-mail et de ses pi??ces jointes est destin?? ?? l'usage exclusif du > (des) destinataire(s) express??ment d??sign??(s) comme tel(s). En cas de r??ception de cet > e-mail par erreur, le signaler ?? son exp??diteur et ne pas en divulguer le contenu. > L'absence de virus a ??t?? v??rifi?? ?? l'??mission du message. Il convient n??anmoins de > v??rifier l'absence de corruption ?? sa r??ception. > > The contents of this email and any attachments are confidential. They are intended for > the named recipient(s) only. If you have received this email in error please notify the > system manager or the sender immediately and do not disclose the contents to > anyone or make copies. eSafe scanned this email for viruses, vandals and malicious > content. > *** > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html