Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
## Rows: 798 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): id, payload
## dbl (1): timestamp
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
10.2c
head(dat, 1)
## # A tibble: 1 × 3
## id timestamp payload
## <chr> <dbl> <chr>
## 1 am72 1151064476 017202f979afdb4cfb
10.2d
The number represents the seconds from the start of 1970 that have elapsed to that point
dat %>%
mutate(dttm = parse_date_time("1970-1-1 0:0:00",
orders = "%Y-%m-%d %H:%M:%S",
tz = "GMT") + timestamp)
## # A tibble: 798 × 4
## id timestamp payload dttm
## <chr> <dbl> <chr> <dttm>
## 1 am72 1151064476 017202f979afdb4cfb 2006-06-23 12:07:56
## 2 am72 1151066276 016e02f9b55fdb508b 2006-06-23 12:37:56
## 3 am72 1151068076 016302f9bd1fdb512e 2006-06-23 13:07:56
## 4 am72 1151069876 015f02f9cc5fdb50c6 2006-06-23 13:37:56
## 5 am72 1151071675 015002f9c98fdb508e 2006-06-23 14:07:55
## 6 am72 1151073475 014102f9cc9fdb5065 2006-06-23 14:37:55
## 7 am72 1151075275 012b02f9ccbfdb509b 2006-06-23 15:07:55
## 8 am72 1151077075 011902f9b40fdb51e7 2006-06-23 15:37:55
## 9 am72 1151078875 010602f9a6afdb5360 2006-06-23 16:07:55
## 10 am72 1151080675 00f702f9a2ffdb53be 2006-06-23 16:37:55
## # ℹ 788 more rows
10.2e
The payload strings represent in hexadecimal, the temperature as well as longitude and latitude that the observation was taken in.
dat <- dat %>%
mutate(temp_hex = str_sub(payload, 1, 4),
lon_hex = str_sub(payload, 5, 11),
lat_hex = str_sub(payload, 12, 18))
10.2d,e
myFun <- function(x) {
output <- hex2integer(x) / 1e5
return(output)
}
10.2f
#Splitting into latitude and longitude.
dat <- dat %>%
mutate(lon = map_dbl(lon_hex, myFun),
lat = map_dbl(lat_hex, myFun))
#Getting correct temperature
dat <- dat %>%
mutate(temp_hex = strtoi(temp_hex, base = 16L) / 10)
10.2g
The map displays elephant movements based on colour. Green = am72, Red = am160.
## Assuming "lon" and "lat" are longitude and latitude, respectively