type count 0 20 1 15 0 10 1 35 0 28 I would like to create two vectors from the data above. For example, type1=c(15, 35) and type0 = c(20, 10, 28). Can any one help Raphael
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
---------- Forwarded message ---------- From: Alexander Nervedi <alexnerdy at hotmail.com> Date: Jun 30, 2006 4:56 PM Subject: time series patterns To: raphael.fraser at gmail.com 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 _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
Does this do what you want? It creates a 'list' with the vectors:> x <- 'type count+ 0 20 + 1 15 + 0 10 + 1 35 + 0 28 + '> x <- read.table(textConnection(x), header=TRUE) > xtype count 1 0 20 2 1 15 3 0 10 4 1 35 5 0 28> type <- split(x$count, x$type) > type$`0` [1] 20 10 28 $`1` [1] 15 35> type[['0']][1] 20 10 28> type[['1']][1] 15 35>On 6/30/06, Raphael Fraser <raphael.fraser@gmail.com> wrote:> > type count > 0 20 > 1 15 > 0 10 > 1 35 > 0 28 > > I would like to create two vectors from the data above. For example, > type1=c(15, 35) and type0 = c(20, 10, 28). Can any one help > > Raphael > > ______________________________________________ > 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 >-- Jim Holtman Cincinnati, OH +1 513 646 9390 (Cell) +1 513 247 0281 (Home) What is the problem you are trying to solve? [[alternative HTML version deleted]]