我是一个R编程的初学者。我正试图获取数据与时间。我已经使用了
select(hrsr, mid, sr) %>% arrange(sr) %>% filter(Hours > "01:00" & Hours < "03:00")
从下表中获取这个时间戳之间的数据行。
mid hr sr t s Hours
<chr> <dttm> <dbl> <dbl> <dbl> <chr>
1 countrydelight 2020-02-12 00:00:00 75 36 27 00:00
2 countrydelight 2020-02-12 01:00:00 79.8 104 83 01:00
3 countrydelight 2020-02-12 02:00:00 78.6 131 103 02:00
4 countrydelight 2020-02-12 03:00:00 78.7 136 107 03:00
5 countrydelight 2020-02-12 04:00:00 79.4 160 127 04:00
6 countrydelight 2020-02-12 05:00:00 76.8 263 202 05:00
7 countrydelight 2020-02-12 06:00:00 76.3 278 212 06:00
得到下面的错误。
Error: Problem with `filter()` input `..1`.
x Input `..1` must be of size 70 or 1, not size 573.
ℹ Input `..1` is `Hours > "01:00" & Hours < "03:00"`.
ℹ The error occured in group 1: mid = "countrydelight".
Run `rlang::last_error()` to see where the error occurred.
看来,这里主要有两个问题。首先,你从数据集'hrsr'中选择了'mid'和'sr'列,但却试图在'Hours'列上进行过滤。第二,'Hours'是一个字符列,所以使用'<'和'>'是行不通的。
试着使用这段代码,大概可以解决这个问题。
hrsr %>%
filter(lubridate::hour(hr) > 1 % lubridate::hour(hr) < 3) %>%
arrange(sr) %>%
select(mid, sr)