I have a data frame of counts of different classifications of ship on specific dates at certain distances off shore (DOS), e.g. 0-12nm and 0-100nm - I would like to subtract the ships within the 0-12nm DOS from 0-100nm, so that I can calculate how many e.g. "passenger" ships were only in 12-100nm on each date. Once that is complete i would like to how many total passenger, cargo etc ships were counted within each DOS for the total time period... I can work out a really laborious ways to do this, but I am pretty sure with the mutate and summarize functions in dplyr there is a more efficient way to run this...
here is an dummy data frame:
df<- structure(list(date = structure(c(17622, 17623, 17624, 17625,
17626, 17627, 17622, 17623, 17624, 17625, 17626, 17627), class = "Date"),
`Passenger(6X)` = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
`Cargo(7X)` = c(2, 0, 2, 2, 2, 3, 5, 4, 7, 6, 7, 4), `Tanker(8X)` = c(0,
0, 0, 0, 0, 0, 0, 3, 1, 0, 1, 0), Otherb = c(`5` = 0, `6` = 0,
`7` = 0, `8` = 0, `9` = 0, `10` = 0, `144` = 0, `154` = 0,
`164` = 0, `174` = 0, `184` = 0, `194` = 0), DOS = c("0-12nm",
"0-12nm", "0-12nm", "0-12nm", "0-12nm", "0-12nm", "0-100nm",
"0-100nm", "0-100nm", "0-100nm", "0-100nm", "0-100nm")), class = "data.frame", row.names = c(1L,
2L, 3L, 4L, 5L, 6L, 1454L, 1455L, 1456L, 1457L, 1458L, 1459L))
In this example on the 1st of April 2018 cargo ships in 12-100nm should be 3 - the output could be in the form of new columns etc. ... within my real data set i actually have 4 different distances offshore and over a year of dates.... so I think dplyr is the best way to go for this - any help would be appreciated.