Re: [R] Refer to previous row

2013-01-07 Thread William Dunlap
...@r-project.org] On > Behalf > Of Paolo Donatelli > Sent: Monday, January 07, 2013 5:34 AM > To: r-help@r-project.org > Subject: [R] Refer to previous row > > Hi all, > > I have a very basic doubt -- but still, I am a newby! > > My question is about referrin

Re: [R] Refer to previous row

2013-01-07 Thread Duncan Murdoch
On 07/01/2013 8:33 AM, Paolo Donatelli wrote: Hi all, I have a very basic doubt -- but still, I am a newby! My question is about referring to the previous row: in a sample as the following... ID X1 X2 1 A 12 2 A 6 3 A 10 1 B 17 2 B 19 1 C 22 1 D 13 2 D 19 3

Re: [R] Refer to previous row

2013-01-07 Thread Berend Hasselman
On 07-01-2013, at 14:33, Paolo Donatelli wrote: > Hi all, > > I have a very basic doubt -- but still, I am a newby! > > My question is about referring to the previous row: in a sample as the > following... > > ID X1 X2 > 1 A 12 > 2 A 6 > 3 A 10 > 1 B 17 > 2 B 19 > 1 C

Re: [R] Refer to previous row

2013-01-07 Thread David Winsemius
On Jan 7, 2013, at 5:33 AM, Paolo Donatelli wrote: Hi all, I have a very basic doubt -- but still, I am a newby! My question is about referring to the previous row: in a sample as the following... ID X1 X2 1 A 12 2 A 6 3 A 10 1 B 17 2 B 19 1 C 22 1 D 13 2 D

Re: [R] Refer to previous row

2013-01-07 Thread jim holtman
try this > x <- read.table(text = 'ID X1 X2 + 1 A 12 + 2 A 6 + 3 A 10 + 1 B 17 + 2 B 19 + 1 C 22 + 1 D 13 + 2 D 19 + 3 D 21', header = TRUE, as.is = TRUE) > x$X3 <- c(0, diff(x$ID) <= 0) > x ID X1 X2 X3 1 1 A 12 0 2 2 A 6 0 3 3 A 10 0 4 1 B 17

Re: [R] Refer to previous row

2013-01-07 Thread Rui Barradas
Hello, Try the following. dat$X3 <- c(0L, dat$ID[-1] <= dat$ID[-nrow(dat)]) Hope this helps, Rui Barradas Em 07-01-2013 13:33, Paolo Donatelli escreveu: Hi all, I have a very basic doubt -- but still, I am a newby! My question is about referring to the previous row: in a sample as the foll

[R] Refer to previous row

2013-01-07 Thread Paolo Donatelli
Hi all, I have a very basic doubt -- but still, I am a newby! My question is about referring to the previous row: in a sample as the following... ID X1 X2 1 A 12 2 A 6 3 A 10 1 B 17 2 B 19 1 C 22 1 D 13 2 D 19 3 D 21 ... I would like to create a dummy varia