-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateEdgeLists.Rmd
64 lines (51 loc) · 1.7 KB
/
GenerateEdgeLists.Rmd
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
---
title: "Generate Edge Lists"
author: "Lauren White"
date: "April 10, 2018"
output: html_document
---
##Load data
```{r}
setwd("C:/Users/law2y/OneDrive/R Code/FrogNetworks")
cwc<-read.csv("CountsWithComplexes.csv")
cwoc<-read.csv("CountsWithoutComplexes.csv")
#drop columns that got imported for csv files for some reason
cwc <- subset(cwc, select = -c(X,X.1) )
cwoc <- subset(cwoc, select = -c(X,X.1) )
unique(cwc$Species.ID) #how many unique species?
length(unique(cwc$Transect))
dates<-unique(cwc$Date)
#create separate column that combines transect + stop location
cwc$transectstop<- paste(cwc$Transect,cwc$Stop, sep="-")
cwoc$transectstop<- paste(cwoc$Transect,cwoc$Stop, sep="-")
```
##Generate edgelist
Which species have called on same date at same transect & stop?
Beware: this takes a while to run.
```{r, eval=FALSE}
dates<-unique(cwc$Date) #how many dates of observation in dataset?
#With complexes
edgelist<-NULL
for(i in 1:length(dates)){
sub_cwc<-cwc[which(cwc$Date==dates[i]),]
edgelist_sub<-data.frame(Species=sub_cwc$Species, Location=sub_cwc$transectstop)
edgelist<-rbind(edgelist, edgelist_sub)
#browser()
}
write.csv(edgelist,file="frogedgelist.csv")
#Without complexes
dates<-unique(cwoc$Date) #how many dates of observation in dataset?
edgelist<-NULL
for(i in 1:length(dates)){
sub_cwoc<-cwoc[which(cwoc$Date==dates[i]),]
edgelist_sub<-data.frame(Species=sub_cwoc$Species, Location=sub_cwoc$transectstop)
edgelist<-rbind(edgelist, edgelist_sub)
#browser()
}
write.csv(edgelist,file="frogedgelist_cwoc.csv")
```
Or load edgelist
```{r}
edgelist<-read.csv("frogedgelist.csv")
#edgelist<-read.csv("frogedgelist_cwoc.csv")
```