forked from astaaudzi/RLSanalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRLS_grouping_sites.R
More file actions
31 lines (25 loc) · 985 Bytes
/
RLS_grouping_sites.R
File metadata and controls
31 lines (25 loc) · 985 Bytes
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
# TASK: group the sites into more manageble sites
rm(list=ls())
list.files()
list.of.packages <- c("tidyverse", "dplyr", "ggplot2")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
lapply(list.of.packages, require, character.only = TRUE)
d <- read.csv("siteData.csv")
head(d)
d2 <- d %>% select(SiteCode, Mean.lattitude, Mean.longitude, Wave.exposure,
No.vertebrate.sp, Min.depth, Mean.visibility, nutrients,
chlomean, sstmean, sstrange)
d2 <- d2[!duplicated(d2), ]
head(d2)
plot(d2$Wave.exposure) #almost categorical
plot(d2)
d3 <- na.omit(d2)
set.seed(20)
clus <- kmeans(d3[,-1], 3, nstart = 20)
d2$cluster <- clus$cluster
d3[match(d3$SiteCode, d2$SiteCode),]$cluster <- clus$cluster
length(unique(d2$SiteCode))
which(table(d2$SiteCode) ==2)
d %>% filter(SiteCode=="1617")
nrow(d2[match(na.omit(d2)$SiteCode, d2$SiteCode),]$cluster)