owned this note
owned this note
Published
Linked with GitHub
> # INBO CODING CLUB
23 April, 2019
Welcome! Yes very welcome
### Share your code snippet
(*you can copy paste this example and add your code further down, but do not fill in your code in this section*)
```r
# example
library(tidyverse)
```
## CHALLENGE 1
### Emma
```
library(lubridate)
test <- occs %>%
filter(month(eventDate) == 6 &
species %in% c("Lycopus europaeus", "Phragmites australis",
"Cymatia bonsdorffi", "Lemna minor") &
is.na(issue)) %>%
select(scientificName, decimalLatitude, decimalLongitude, coordinateUncertaintyInMeters,
eventDate, year, identifiedBy, speciesKey, issue)
```
### Wouter
```
str(occs)
obs <- occs %>% select(scientificName, decimalLatitude, decimalLongitude,coordinateUncertaintyInMeters,
eventDate, year, identifiedBy, speciesKey, month, species, issue) %>%
filter(month==6,
species %in% c("Lycopus europaeus", "Phragmites australis", "Cymatia bonsdorffi","Lemna minor"),
is.na(issue))
head(obs)
```
## CHALLENGE 2
### Tom
```
chl2<-occs %>%
select(scientificName, decimalLatitude, decimalLongitude,
coordinateUncertaintyInMeters, eventDate, year,
issue) %>%
mutate(grid_resolution_km=sqrt(2)*coordinateUncertaintyInMeters/1000) %>%
arrange(desc(eventDate))
chl2$grid_resolution_km<-(sqrt(2)* chl2$coordinateUncertaintyInMeters/1000)
chl2<-chl2[order(chl2$eventDate, decreasing = TRUE),]
```
### Anneleen
```
occselect2<-occs %>%
select(scientificName, decimalLatitude, decimalLongitude,
coordinateUncertaintyInMeters, eventDate, year,
issue) %>%
mutate(gridresolution = sqrt(2)* coordinateUncertaintyInMeters/1000) %>%
arrange(eventDate)
##Wouter
occs %>%
mutate(gridresolution_km = sqrt(2) * coordinateUncertaintyInMeters/1000)
```
## CHALLENGE 3
### Anneleen
```
occselect3<-occs %>%
select(scientificName, genus, decimalLatitude, decimalLongitude,
coordinateUncertaintyInMeters, eventDate, year, month,
identifiedBy, speciesKey, issue) %>%
group_by(year) %>%
summarise(available_for_each_year =n())
```
### Kan ook zonder een group_by
```
occs %>%
select(scientificName, genus, decimalLatitude, decimalLongitude,
coordinateUncertaintyInMeters, eventDate, year, month,
identifiedBy, speciesKey, issue) %>%
count(year)
```
## BONUS
### Emma
```
surveys <- read_csv("data/20180222_surveys.csv") %>%
filter(!is.na(weight)) %>%
group_by(species_id) %>%
summarise(aantal = n(),
Mean = mean(weight),
Median = median(weight))
```
## CHALLENGE 4 by Sander en Anneleen
```
dataset_grofwild <- read_csv2("data/grofwild.csv")
```
1. Haal de de kolommen 'variabelen' uit de data
2. Vertaal de afkortingen naar provincie en geslacht
Succes!
###Anneleen
```
grofwildselect <- dataset_grofwild %>%
select(contains("Var")) %>%
rename(Provincie=Variabele.11,
Geslacht = Variabele.18,
Soort = Variabele.4) %>%
mutate (Provincie = case_when (Provincie == "ANT" ~ "Antwerpen",
Provincie == "LIM" ~ "Limburg",
Provincie == "VLB" ~ "Vlaams-Brabant",
Provincie == "WVL" ~ "West-Vlaanderen")) %>%
mutate(Geslacht = case_when (Geslacht == "F" ~ "Vrouwelijk",
Geslacht == "M" ~ "Mannelijk",
Geslacht == "O" ~ "Onbekend"))
```
### Ivy
```
grofwild <- read_csv2("data/grofwild.csv") %>%
select(starts_with("Variabele"))
grofwild2 <- grofwild %>%
transmute(Soort = `Variabele 4`,
Provincie = factor(`Variabele 11`,
labels = c("Antwerpen", "Limburg",
"Vlaams-Brabant", "West-Vlaanderen"),
levels = c("ANT", "LIM", "VLB", "WVL")),
Geslacht = factor(`Variabele 18`,
labels = c("mannelijk", "vrouwelijk",
"onbekend"),
levels = c("M", "F", "O")))
```
### with recode
```
grofwild <- dataset_grofwild %>%
select(starts_with("Var")) %>%
rename(species = "Variabele 4",
province = "Variabele 11",
sex = "Variabele 18") %>%
mutate(province =
recode(province,
"ANT" = "Antwerpen",
"LIM" = "Limburg"))
```