 <pre><code>library(data.table) library(reshape2) library(lubridate) df = fread("/storage/Downloads/Watertable_fluctuations_All_Original.txt", skip = 1, header = T) # dropbox file df = df[, date := dmy(date)] dfm = melt(df, id.vars = "date", value.name = "water.level") wl.threshold = -0.22 dfm[water.level &lt; wl.threshold,.N, keyby = variable] # count per measuring station # bonus library(openair) timePlot(dfm[variable == "Yel342(2010)"], pollutant = "water.level", smooth = T, ref.y = wl.threshold) </code></pre> <p><img src="https://i.stack.imgur.com/kNSal.jpg" alt="enter image description here"></p>