计算下雨时间"来自每分钟的数据

时间:2018-03-28 10:12:08

标签: r

我为再次发布这篇文章而道歉,但我在上一篇文章中犯了一系列错误。

我的数据每分钟有降水量。当我计算每小时平均值时,我想将此计算为降雨量> 0时的降雨分钟总和(以小时表示)。

非常感谢帮助。提前谢谢你:

    > metsacbo[1021:1085,]
         date               press  temp  ws wd   u%  precipitation 
    1021 2017-06-06 17:00:00 963.9 19.6  2 344.3 55.6    0.00           
    1022 2017-06-06 17:01:00 980.2 19.9  2 348.3 56.0    0.00           
    1023 2017-06-06 17:02:00 980.2 19.9  2 355.4 55.8    0.00           
    1024 2017-06-06 17:03:00 980.2 19.8  2 351.8 54.0    0.00           
    1025 2017-06-06 17:04:00 980.1 19.8  2 354.4 54.2    0.00           
    1026 2017-06-06 17:05:00 963.8 19.5  2   2.8 54.1    0.00           
    1027 2017-06-06 17:06:00 980.1 19.8  3 345.3 54.7    0.00           
    1028 2017-06-06 17:07:00 980.0 19.7  2 345.8 54.8    0.00           
    1029 2017-06-06 17:08:00 979.9 19.7  2 352.5 55.1    0.00           
    1030 2017-06-06 17:09:00 979.9 19.7  2 355.8 55.9    0.00           
    1031 2017-06-06 17:10:00 979.9 19.7  2   1.8 56.3    0.00           
    1032 2017-06-06 17:11:00 980.0 19.6  2   3.7 56.1    0.00           
    1033 2017-06-06 17:12:00 980.0 19.6  2 354.9 56.0    0.00           
    1034 2017-06-06 17:13:00 980.0 19.6  2 357.1 56.6    0.00           
    1035 2017-06-06 17:14:00 979.9 19.6  2 359.9 57.1    0.00           
    1036 2017-06-06 17:15:00 979.9 19.6  2   3.4 57.5    0.00           
    1037 2017-06-06 17:16:00 979.8 19.6  2 340.0 58.1    0.00           
    1038 2017-06-06 17:17:00 979.8 19.6  3 355.4 58.0    0.00           
    1039 2017-06-06 17:18:00 979.8 19.6  2 336.4 58.0    0.00           
    1040 2017-06-06 17:19:00 979.9 19.6  2 337.9 58.0    0.00           
    1041 2017-06-06 17:20:00 980.0 19.6  3 336.9 57.5    0.02           
    1042 2017-06-06 17:21:00 980.2 19.6  2 334.2 56.3    0.00           
    1043 2017-06-06 17:22:00 980.2 19.5  2 347.3 55.8    0.00           
    1044 2017-06-06 17:23:00 980.2 19.5  2 354.7 56.3    0.00           
    1045 2017-06-06 17:24:00 980.1 19.5  2 348.0 56.7    0.00           
    1046 2017-06-06 17:25:00 979.9 19.5  1   2.7 57.1    0.00           
    1047 2017-06-06 17:26:00 979.8 19.4  3 357.3 57.0    0.00           
    1048 2017-06-06 17:27:00 963.4 19.1  3   1.6 55.8    0.01           
    1049 2017-06-06 17:28:00 963.3 19.0  2   8.4 56.7    0.01           
    1050 2017-06-06 17:29:00 963.3 19.0  2 358.8 57.2    0.00           
    1051 2017-06-06 17:30:00 979.6 19.2  2 352.1 58.0    0.00           
    1052 2017-06-06 17:31:00 979.6 19.2  2 344.1 59.1    0.05           
    1053 2017-06-06 17:32:00 979.6 19.2  3 343.3 60.3    0.23           
    1054 2017-06-06 17:33:00 979.7 19.1  3 346.3 59.9    0.40           
    1055 2017-06-06 17:34:00 979.8 18.9  4 343.1 60.6    0.67           
    1056 2017-06-06 17:35:00 979.9 18.6  3 347.2 62.6    0.52           
    1057 2017-06-06 17:36:00 980.0 18.4  3 340.5 64.7    0.53           
    1058 2017-06-06 17:37:00 980.0 18.1  3 337.5 65.8    0.90           
    1059 2017-06-06 17:38:00 980.2 17.9  2 309.4 67.3    0.51           
    1060 2017-06-06 17:39:00 980.4 17.6  2 321.1 68.9    0.74          
    1061 2017-06-06 17:40:00 980.6 17.3  2 306.1 69.4    0.70           
    1062 2017-06-06 17:41:00 980.8 17.0  2 252.6 70.2    1.29           
    1063 2017-06-06 17:42:00 981.0 16.7  2 226.8 71.2    1.60           
    1064 2017-06-06 17:43:00 981.2 16.4  2 260.7 72.1    1.26           
    1065 2017-06-06 17:44:00 981.1 16.1  2 293.0 73.1    1.77           
    1066 2017-06-06 17:45:00 980.7 15.8  2 324.6 73.7    1.88           
    1067 2017-06-06 17:46:00 980.4 15.5  3 348.7 74.5    1.21           
    1068 2017-06-06 17:47:00 963.7 15.0  2 351.4 74.6    1.03           
    1069 2017-06-06 17:48:00 980.0 15.1  3 329.3 77.5    0.93                   
    1070 2017-06-06 17:49:00 980.0 15.0  1 352.5 78.6    0.71           
    1071 2017-06-06 17:50:00 979.9 15.0  2 343.7 79.4    0.53           
    1072 2017-06-06 17:51:00 979.9 15.0  2 334.1 79.8    0.12           
    1073 2017-06-06 17:52:00 979.9 15.1  2 358.4 80.1    0.05          
    1074 2017-06-06 17:53:00 979.9 15.1  2 345.6 80.0    0.01           
    1075 2017-06-06 17:54:00 979.9 15.2  2   0.4 79.4    0.01          
    1076 2017-06-06 17:55:00 979.8 15.3  2 354.4 78.7    0.00           
    1077 2017-06-06 17:56:00 979.7 15.4  2 355.8 78.1    0.00           
    1078 2017-06-06 17:57:00 979.7 15.5  1   8.9 77.8    0.00           
    1079 2017-06-06 17:58:00 979.7 15.6  1  32.4 77.4    0.00           
    1080 2017-06-06 17:59:00 979.7 15.7  1  49.5 77.0    0.00           
    1081 2017-06-06 18:00:00 979.8 15.8  1  53.1 76.8    0.00           
    1082 2017-06-06 18:01:00 979.8 15.8  1  34.6 77.0    0.00           
    1083 2017-06-06 18:02:00 979.9 15.9  2  35.0 76.8    0.00           
    1084 2017-06-06 18:03:00 979.9 15.9  2  10.0 76.4    0.00           
    1085 2017-06-06 18:04:00 980.0 15.9  2   3.2 76.5    0.00 

当我计算每小时平均值时,这是我想要的结果。

在" time prec"我希望得到每小时下雨事件的分钟数。

  

头(dmeth,20)

     

A tibble:20 x 8

约会温度与你同在。 PREC。时间准备。(h)                                    1 2017-06-06 00:00:00 984. 17.8 0.783 15.3 72.8 0。0  2 2017-06-06 01:00:00 979. 17.5 0.550 32.1 77.0 0. 0  3 2017-06-06 02:00:00 982. 17.5 0.800 0.567 74.9 0。0  4 2017-06-06 03:00:00 982. 17.5 0.717 358. 78.1 0. 0  5 2017-06-06 04:00:00 982. 17.7 0.583 40.7 73.7 0。0  6 2017-06-06 05:00:00 981. 17.6 0.767 354. 76.1 0。0  7 2017-06-06 06:00:00 980. 17.8 0.700 6.19 74.2 0。0  8 2017-06-06 07:00:00 981. 18.1 0.683 26.8 73.3 0. 0  9 2017-06-06 08:00:00 981. 18.8 0.800 26.4 69.5 0。0 10 2017-06-06 09:00:00 981. 19.1 0.100 45.9 72.4 0. 0 11 2017-06-06 10:00:00 979. 19.4 0.317 351. 70.4 0. 0 12 2017-06-06 11:00:00 981.20.0 1.20 41.3 67.2 0.120 0.03 13 2017-06-06 12:00:00 980. 21.4 1.58 121. 58.2 0。0 14 2017-06-06 13:00:00 979. 22.0 1.98 123. 59.2 0。0 15 2017-06-06 14:00:00 979. 21.8 1.78 120. 59.8 0。0 16 2017-06-06 15:00:00 978. 20.0 1.55 122. 69.8 8.15 0.43 17 2017-06-06 16:00:00 979. 20.4 1.68 3.33 64.9 0。0 18 2017-06-06 17:00:00 978. 18.1 2.15 345. 64.0 17.7 0.45 19 2017-06-06 18:00:00 978. 16.8 2.07 15.2 74.4 0。0 20 2017-06-06 19:00:00 980. 17.0 2.73 357. 71.4 6.18 0.52

1 个答案:

答案 0 :(得分:1)

由于某些原因,你的数据正在崩溃,所以让我们模拟一下:

UITapGestureRecognizer

现在,由于您的数据结构的方式,如果您想要有一些降水的小时数(precipitation <- sample(0:19, 180, replace = TRUE, prob = c(0.9, rep(0.1/19, 19)))/10 date <- round(Sys.time(), "min") + seq_len(180)*60 df <- data.frame(date, precipitation) ),您可以将逻辑向量相加并除以60:

df$precipitation > 0

如果你想让它成为班级sum(df$precipitation > 0) / 60 的一个对象,只需将其变为一个,单位为

"difftime"

现在它将作为difftime打印。

我一直试图理解你想要的行为......我想它可能是:

x <- sum(df$precipitation > 0) / 60
class(x) <- "difftime"
attr(x, which = "units") <- "hours"

您想要的表格(编辑您的帖子以包含它,不要将其添加为答案)会将该列显示为数字,并为行提供df$time_prec <- as.numeric(df$precipitation > 0) head(df) date precipitation time_prec 1 2018-03-28 11:13:00 0.0 0 2 2018-03-28 11:14:00 0.0 0 3 2018-03-28 11:15:00 0.0 0 4 2018-03-28 11:16:00 0.0 0 5 2018-03-28 11:17:00 0.9 1 6 2018-03-28 11:18:00 0.0 0 没有降水,对于有一些降水的行是空白的。你不能为数字列设置一个空白值(你可以为字符,但我不建议它),所以在这里我们将它设为1,用于有一些降水的行。

相关问题