I want to have the value and dates corresponding to number of occurences. I use this fonction that does what i want very well.
count <- function(df, min_build, min_days) {
sum(with(rle(df$build > min_build), values & lengths >= min_days))}
My data looks like:
data = data.frame(station, build, dates, Year, Month, day)
station build dates Year Month day
1 Bariko 24.5 1960-01-01 1960 1 1
2 Bariko 29.1 1960-01-02 1960 1 2
3 Bariko 26.4 1960-01-03 1960 1 3
4 Bariko 29.0 1960-01-04 1960 1 4
5 Bariko 22.0 1960-01-05 1960 1 5
6 Bariko 25.9 1960-01-06 1960 1 6
7 Bariko 24.2 1960-01-07 1960 1 7
8 Bariko 23.9 1960-01-08 1960 1 8
9 Bariko 24.4 1960-01-09 1960 1 9
10 Bariko 24.0 1960-01-10 1960 1 10
11 Bariko 24.2 1960-01-11 1960 1 11
12 Bariko 24.8 1960-01-12 1960 1 12
13 Bariko 25.4 1960-01-13 1960 1 13
h <- count(data, 24, 4) # I have the right number but for all 10 years(1960-1969)
#I split my data by year to have the value for each year.
g <- data$Year
l <- split(data, g)
k=l$'1962'
h <- count(k, 24, 4) # I repeat this 10 times (for each year)
My questions:
1.How can I detect days that correspond to my count?
2.How can I loop to get all the value in 2 columns (Year,Value)?