Re: [R] Creating Vectors

From: Alexander Nervedi <alexnerdy_at_hotmail.com>
Date: Sat 01 Jul 2006 - 07:57:35 EST


Hi all.

I have a factor variable distributed over time. I am looking for an elegant way to code duration of a state. Suppose,

>rainfall.shocks <- factor(sample(c(1,2,3), size = 15, replace = TRUE, prob
>= unit.p),

+                  label = c("Drought", "Normal", "High"))

>
>rainfall.shocks

[1] Normal High High Drought Normal Normal High Normal Drought [10] Normal Drought Normal Normal Normal Normal

So capture the duration of say drought, I'd need a variable that is able to keep track of rainfall.shocks as well as its past values. I was wondering if there is any obvious way to do this. the Drought variable in this case would have values

0 0 0 1 0 0 0 0 1 0 1 0 0 0 0

many thanks for the suggestions you are likely to make.

Alexander Nervedi



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jul 01 09:14:04 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 01 Jul 2006 - 10:14:15 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.