-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleaning_scoots.R
More file actions
50 lines (32 loc) · 1.24 KB
/
Cleaning_scoots.R
File metadata and controls
50 lines (32 loc) · 1.24 KB
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
# Loading libraries: ------------------------------------------------------
library(tidyverse)
library(lubridate)
library(here)
# Create a chr vector of file names: --------------------------------------
myfiles = list.files(path=here("Data","scoot_data"),
pattern="*.csv",
full.names=TRUE)
myfiles
# Read in files, bind rows, and add column for file name: -----------------
df <- do.call("rbind", lapply(myfiles, function(x) {
dat <- read.csv(x, header=TRUE)
dat$fileName <- tools::file_path_sans_ext(basename(x))
dat
}))
# Extract scn and read date as POSIXct: -----------------------------------
scoot_data <- df %>%
janitor::clean_names() %>%
mutate(date = lubridate::dmy_hms(date),
scn = str_split(file_name, pattern = " "),
scn = lapply(scn, `[`, 2),
scn = unlist(scn)) %>%
select(-x,
-file_name)
# Adding in loop info: ----------------------------------------------------
loop_info <- read_csv(here("Data","loop_info.csv")) %>%
janitor::clean_names()
scoot_data <- scoot_data %>%
left_join(loop_info, by = 'scn')
# Saving as csv: ----------------------------------------------------------
scoot_data %>%
write_csv(here("Data", "cleaned_scoot.csv"))