Q:

Find & sum range of values > 0 which aren't interrupted by specific quantity of zeros

I have a CSV file which stores precipitation data in mm per day for over 80 years like this:
19980720;0
19980721;5.1
19980722;2
19980723;21.1
19980724;3.4
19980725;0
19980726;0
19980727;1.2
19980728;0.2
19980729;0
19980730;0
19980731;0
19980801;2
19980802;5.6
19980803;10
19980804;15
19980805;14.6
19980806;13
19980807;0
19980808;0

I already loaded the data in R. Now I want to find periods with continuous rain. To do so I thought about summing up the rainfall of days which are interrupted by at least two days without any rainfall.
How can I find those periods?
EDIT: For the example data the output could be something like this:
60.2
31.6
1.4

which are the summarized and sorted values of the three periods with continuous rain in my example. Maybe it is possible to add the start and/or end date when the specific event happend:
19980801 19980806 60.2
19980721 19980724 31.6
19980727 19980728 1.4

A:

In order to get only the cumulative rainfullfall for periods of sustained rainfall, you need to create a vector indicating whether a day belongs to such a period.
NOTE: In order to illustrate this, I created a slightly different dataset where in the last period of rain there is one day without rain (see below).
Using data.table you could do:
setDT(mydf)[, sus.rf := !(rf==0 & (shift(rf,1L,type="lag",fill=0)==0 | shift(rf,1L,type="lead",fill=0)==0))
            ][, id:=rleid(sus.rf)
              ][sus.rf==TRUE, .(start=dates[1], end=dates[.N], sum.rf=sum(rf)), id]

which gives:
   id    start      end sum.rf
1:  2 19980721 19980724   31.6
2:  4 19980727 19980728    1.4
3:  6 19980801 19980806   45.6

Suppose you want to sum up the days which are interrupted by at least 3 days without rain, you could do:
setDT(mydf)[, sus.rf := !(rf==0 & (shift(rf,1L,type="lag",fill=0)==0 | shift(rf,1L,type="lead",fill=0)==0))
            ][, days := .N, rleid(sus.rf)
              ][sus.rf==FALSE & days < 3, sus.rf := TRUE
                ][, .(start=dates[1], end=dates[.N], sum.rf=sum(rf)), rleid(sus.rf)][sum.rf!=0][]

which gives:
   rleid    start      end sum.rf
1:     1 19980720 19980728   33.0
2:     3 19980801 19980808   45.6

Used data:
mydf <- structure(list(dates = c(19980720L, 19980721L, 19980722L, 19980723L, 
                                 19980724L, 19980725L, 19980726L, 19980727L, 19980728L, 19980729L, 
                                 19980730L, 19980731L, 19980801L, 19980802L, 19980803L, 19980804L, 
                                 19980805L, 19980806L, 19980807L, 19980808L), 
                       rf = c(0, 5.1, 2, 21.1, 3.4, 0, 0, 1.2, 0.2, 0, 0, 0, 2, 5.6, 10, 15, 0, 13, 0, 0)), 
                  .Names = c("dates", "rf"), row.names = c(NA, -20L), class = "data.frame")

A:

We can use data.table.  Convert the 'data.frame' to 'data.table' (setDT(d1)), create a grouping column with rleid based on the logical index in 'v2' (!v2).  Remove the rows corresponding to '0' values in 'v2', grouped by 'i1', we get the sum of 'v2' and the first and last (v1[1], v1[.N]) elements in the 'v1'.  Assign the 'i1' to NULL  (if needed).
library(data.table)
setDT(d1)[,i1:= rleid(!v2)][v2!=0, 
      list(v1[1], v1[.N],sum(v2)), i1][, i1:= NULL][]
#        V1       V2   V3
#1: 19980721 19980724 31.6
#2: 19980727 19980728  1.4
#3: 19980801 19980806 60.2

data
 d1 <- structure(list(v1 = c(19980720L, 19980721L, 
  19980722L, 19980723L, 
19980724L, 19980725L, 19980726L, 19980727L, 19980728L, 19980729L, 
19980730L, 19980731L, 19980801L, 19980802L, 19980803L, 19980804L, 
19980805L, 19980806L, 19980807L, 19980808L), v2 = c(0, 5.1, 2, 
21.1, 3.4, 0, 0, 1.2, 0.2, 0, 0, 0, 2, 5.6, 10, 15, 14.6, 13, 
0, 0)), .Names = c("v1", "v2"), class = "data.frame", 
row.names = c(NA,  -20L))

A:

This could be another option (load your file using sep = ';' and header = FALSE in read.table)
library(data.table)
dat$V3 = cumsum(c(TRUE, diff(dat$V2)==0))
out = setDT(dat)[, .(a = V1[2L], b = V1[.N-1], c = sum(V2)), by = V3][, -V3, with=FALSE]

This will give
#          a        b    c
#1: 19980721 19980724 31.6
#2: 19980727 19980728  1.4
#3:       NA       NA  0.0
#4: 19980801 19980806 60.2
#5:       NA       NA  0.0

later you can remove rows with NA
like this
out[is.finite(rowSums(out))]

Using base R lapply
dat$V3 = cumsum(c(TRUE, diff(dat$V2)==0))
d1 = split(dat, f=dat$V3)
do.call(rbind, 
  lapply(d1[sapply(d1, function(x) dim(x)[1]) > 1],
        function(x){ out = subset(x, x$V2 != 0); 
        data.frame(a = out$V1[1L], b = out$V1[length(out$V1)], c = sum(out$V2))
  }))

#         a        b    c
#1 19980721 19980724 31.6
#2 19980727 19980728  1.4
#4 19980801 19980806 60.2

