...@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
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
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
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
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
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
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
7 matches
Mail list logo