示例:
1982-01-30 41.04
1982-02-02 45.72
1982-02-03 46.8
1982-02-04 41.04
1982-02-12 39.24
1982-02-17 53.28
1982-02-18 49.68
1982-02-19 40.32
1982-03-01 46.08
1982年2月,有2次是情况(2,3,4)和(17,18,19)。
是否有人知道如何计算并将其放入新表进行进一步分析/绘图?
1982 23
1983 7
1984 11
.
.
.
至少只计算每年的所有日子也会对我有所帮助。
亲切的问候 的Sascha
答案 0 :(得分:1)
以下是识别风暴日(根据您的评论风> 39)和连续三个风暴日的日期的简单方法。
regex=LAN
while IFS= read -r line; do
echo "Read line from grep: $line"
done < <(grep -e "$regex" <database.txt)
您的输出看起来像这样:
#create example data
fakedates <- as.Date("1982-01-01")+(1:730)
fakewind <- sample(1:80, length(fakedates), replace = TRUE)
dateyear <- format(fakedates, "%Y")
df <- data.frame("dates"=fakedates, "maxwind"=fakewind, "year"=dateyear)
#identify 'storm' days where max wind is >39
df$storm <- df$maxwind > 39 #identify storm days
# ensure original data is in chronological order, otherwise you would need to sort first
# e.g. if(is.unsorted(original$dates), sort(original$dates, .... etc)
#identify 3-day storms - undetermined for last two days in the record
df$storm3 <-
c(df$storm[1:(length(df$storm) - 2)] &
df$storm[2:(length(df$storm) - 1)] &
df$storm[3:(length(df$storm))], "unknown", "unknown")
#select all storm day records
dfs <- df[df$storm == TRUE, c(1:3)]
#select only dates of 3-day storms
dfs3 <- df[df$storm3== TRUE,(1:3)]
您可以按年度汇总并执行您需要的任何其他分析,无论是所有风暴日(dfs)还是仅限三天风暴日(dfs3)。
如果你对R更加熟悉,你可以用其他各种方式解决这个问题,例如:与包dplyr