-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTest1.R
More file actions
79 lines (55 loc) · 1.82 KB
/
Copy pathTest1.R
File metadata and controls
79 lines (55 loc) · 1.82 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Cleaning data
# clean names: janitor::clean_names(palmerpenguins::penguins_raw)
# skimr::skim
# tibble - use dplyr::distinct() get rid of repeated rows
# missing data - naniar:: vis_miss()
print("Good morning Hedda!")
library(tidyverse)
library(palmerpenguins)
library(janitor)
library(skimr)
library(naniar)
# Data cleaning
janitor::clean_names(messy_data)
clean_data <- janitor::clean_names(messy_data) # cleans names in header
dplyr::glimpse(clean_data)
out <- skimr::skim(clean_data)
# lower case
clean_data$age <- tolower(clean_data$age)
clean_data$sex <- tolower(clean_data$sex)
# clean capital letters
clean_data <- clean_data %>%
mutate(age = str_replace(age, "j$", "juvenile"),
age = str_replace(age, "a$", "adult"),
species_name = str_replace_all(species_name, "Lagopus muta", "Lagopus lagopus")) %>%
mutate(species_name = str_replace(species_name, "Logopus muta", "Lagopus matu"),
species_name = str_replace(species_name, "Lagopas lagopus", "Lagopus lagopus"))
# Fix date
library(datefixR)
clean_data <- datefixR::fix_date_df(clean_data, "date")
#Deduplication
dim(clean_data)
clean_data_dup <- clean_data |> slice(rep(1:n(), each = 3))
dim(clean_data_dup)
clean_data_undup <- distinct(clean_data_dup)
dim(clean_data_undup)
clean_data |> naniar::vis_miss()
# conflicted package - sorts conflicts between packages
conflicted::conflict_prefer("filter", "dplyr")
# pivot wider - transform to long
smallGame_long <- smallGame %>%
pivot_longer(-c(small_game, contents, interval_year), # m?? legge inn _
names_to = "site",
values_to = "count")
# package styler
# a <- 3 means a sign for 3
# functions
miles_to_km <- function(miles) {
if (is.numeric(miles)){
miles*1.609344
}else{
print("Miles needs to be numeric")
}}
#
##test branching #
jkhihio