fork download
  1. library(dplyr)
  2.  
  3. df <- read.csv("typhoon.csv")
  4.  
  5. df <- df %>%
  6. mutate(date = paste(Year, Month, Day, sep = "-")) %>%
  7. group_by(CycloneNo) %>%
  8. mutate(Hour_lag = lead(Hour),
  9. Hour_lag = ifelse(is.na(Hour_lag), -1, Hour_lag),
  10. # 如果颱風有跨日, 將前一日的18時計為2個int (1 int = 6 hr)
  11. interval = ifelse(Hour == 18 & Hour_lag == 0, 2, 1)
  12. ) %>%
  13. group_by(date) %>%
  14. # 計算每天颱風存在的時數
  15. mutate(Hour_sum = (sum(interval) - 1)*6) %>%
  16. filter(Hour_sum >= 18 & row_number()==1) %>%
  17. ungroup()# your code goes here
Success #stdin #stdout #stderr 0.59s 49932KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Error in file(file, "rt") : cannot open the connection
Calls: read.csv -> read.table -> file
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'typhoon.csv': No such file or directory
Execution halted