Dear All,
Thanks for the useful ideas.
This is how I solved the problem and it works well.
sowdays=function(data,Year){
Year = unique(data$Year)
#gives you sum of rain in 2 consecutive days
twodays <- rowSu
twodays <- c(filter(x,c(1,1),sides=1))
might be more efficient with memory than the embed approach, which might be
important if more than two days were of interest.
---
Jeff NewmillerThe .
Break down your problem into parts:
# compute two-day totals. I use filter here, but there are many ways
twoDayTotal <- function (x, init = 0)
{
# init lets you supply rainfall from day previous to first in x
filter(c(init, x), c(1, 1))[-length(x)]
}
# compute the first time a logical vect
A couple of observations:
1) I'm not sure what the variable i is doing, looks like you are trying
to loop through years but perhaps you left that bit of code out for
clarity.
2) On the first loop of i you are assigning the values of
Samaru56[sow_day,] to all values in Samaru56. For future loops all
Hi, this sound like u are calculating cummulative rainfall, this can also be
done in excel, then import the matrix to R, hope can help,
Franklin, Maseno, Kenya.
On Wednesday, October 15, 2014 1:02 PM, PIKAL Petr
wrote:
Hi
twodays <- rowSums(embed(Samaru56$Rain,2))
gives you sum of rain
Hi
twodays <- rowSums(embed(Samaru56$Rain,2))
gives you sum of rain in 2 cosecutive days
sel <- which(twodays>20)
gives you vector of row numbers in which above condition results in TRUE value
Samaru56[sel,]
selects these rows
Regards
Petr
> -Original Message-
> From: r-help-boun...
6 matches
Mail list logo