Skip to content
Prev 227929 / 398500 Next

Help with a problem

Sorry for not being clear.

In the dataset there are around 100 or so days of data (in the case also rows of data)

I need to make sure that the person meets that c1 is at least 100 AND c2 is at least 8 for 5 of 7 continuous days.

I will play with what I have and see if I can find out how to do this.

Thanks for the help!

Michael
Mike,

I am slightly unclear on what you want to do. Do you want to check rows 
1 and 7 or 1 *to* 7? Should c1 be at least 100 for *any one* or *all* 
rows you are looking at, and same for c2?

You can sort your data like this:
data <- data[order(data$ds),]

Type ?order for help. But also do this for added enlightenment...:

library(fortunes)
fortune("dog")

Next, your analysis on the sorted data frame. As I said, I am not 
entirely clear on what you are looking at, but the following may solve 
your problem with choices "1 to 7" and "any one" above.

foo <- 0
for ( ii in 1:(nrow(data)-8) ) {
   if (any(data$c1[ii+seq(0,6)]>=100) & any(data$c2[ii+seq(0,6)]>=8)) {
     foo <- 1
     break
   }
}

The variable "foo" should contain what you want it to. Look at ?any 
(and, if this does not do what you want it to, at ?all) for further info.

No doubt this could be vectorized, but I think the loop is clear enough.

Good luck!
Stephan



Michael Hess schrieb:
**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues