# Re: [R] Proba( Ut+2=1 / ((Ut+1==1) && (Ut==1))) ?

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.ac.be>
Date: Tue 26 Apr 2005 - 02:22:37 EST

maybe something like this:

x <- sample(c(1, -1), 100, TRUE)
y <- rle(x)
##
ind1 <- y\$length[y\$value == 1]
sum(ind1[ind1 > 2] - 2)
ind2 <- y\$length[y\$value == -1]
##
sum(ind1[ind1 > 2] - 2)

Best,
Dimitris

Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

```Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm

```
• Original Message ----- From: "vincent" <vincent@7d4.com> To: <r-help@stat.math.ethz.ch> Sent: Monday, April 25, 2005 6:03 PM Subject: [R] Proba( Ut+2=1 / ((Ut+1==1) && (Ut==1))) ?

> Dear all,
>
> First I apologize if my question is quite simple,
> but i'm very newbie with R.
>
> I have vectors of the form v = c(1,1,-1,-1,-1,1,1,1,1,-1,1)
> (longer than this one of course).
> The elements are only +1 or -1.
>
> I would like to calculate :
> - the frequencies of -1 occurences after 2 consecutives -1
> - the frequencies of +1 occurences after 2 consecutives +1
>
> It looks probably something like :
> Proba( Ut+2=1 / ((Ut+1==1) && (Ut==1)))
>
> i should/could begin to proceed ?
>
> Thanks
> (Thanks also to the R creators/contributors, this soft
> seems really great !)
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help