-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_preprocessing.Rmd
73 lines (57 loc) · 1.08 KB
/
data_preprocessing.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
title: "R Notebook"
output: html_notebook
---
```{r}
library(readr)
library(data.table)
library(tidyverse)
library(rlist)
library(geosphere)
library(raster)
ships <- read_csv("ships.csv")
```
```{r}
ships <-
ships %>% dplyr::select(ship_type, SHIP_ID, DATETIME, LAT, LON)
```
```{r}
ships <- ships %>%
group_by(SHIP_ID) %>%
mutate(prevLON = lag(LON)) %>%
mutate(prevLAT = lag(LAT)) %>%
mutate(prevDATE = lag(DATETIME))
```
```{r}
#apply(ships, 2, function(x) any(is.na(x)))
```
```{r}
ships <- na.omit(ships)
```
```{r}
ships <-
ships %>% mutate(dist = pointDistance(cbind(prevLON, prevLAT), cbind(LON, LAT), lonlat =
TRUE))
```
```{r}
options(digits = 22)
```
```{r}
ships <- ships %>% group_by(SHIP_ID) %>%
filter(dist == max(dist))
```
```{r}
ships$dist <- round(ships$dist)
```
```{r}
ships <- ships[!duplicated(ships[, c("SHIP_ID")], fromLast = T), ]
```
```{r}
ships$SHIP_ID <- as.character(ships$SHIP_ID)
```
```{r}
saveRDS(ships, file = "ships_calculated.Rds")
```
```{r}
ships <<- readRDS("ships_calculated.Rds")
```