-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequired.jl
46 lines (38 loc) · 1.49 KB
/
required.jl
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
using CSV
using DataFrames
using Plots
using EcologicalNetworks
using EcologicalNetworksPlots
using Distributions
function load_data()
df = CSV.read("WoodEtal_Append1_v2.csv")
# Separate based on WebScale
scale = [df[df.WebScale .== u,:] for u in unique(df.WebScale)]
# select for edge interaction columns only
edgelist_T = scale[1][:, [:PredTSN, :PreyTSN]]
# view all entries that contain "san" in PredTSN
pred_san = edgelist_T[startswith.(edgelist_T.PredTSN, "san"),:]
# remove "san"
pred_san.PredTSN = replace.(pred_san.PredTSN, "san" .=> "")
pred_san
#view unique predID without san
unique(pred_san,1)
edgelist_T.PredTSN == "102" #manually check if in original df
# remove the "san" from the dataframe itself
edgelist_T.PredTSN = replace.(edgelist_T.PredTSN, "san" .=> "")
# Do the same for PreyTSN
backup2 = copy(edgelist_T)
old_ids2 = unique(backup2.PreyTSN)
# keep the indexes before the change
prey_indexes = startswith.(edgelist_T.PreyTSN, "san")
# remove the "san" from the dataframe itself
edgelist_T.PreyTSN = replace.(edgelist_T.PreyTSN, "san" .=> "")
edgelist_T
#check unique preyIDs without san
check_uniques2 = [in(new_id2, old_ids2) for new_id2 in edgelist_T.PreyTSN[prey_indexes]]
filter(isone, check_uniques2)
# convert "string" to "integer"
edgelist_T.PredTSN = parse.(Int64, edgelist_T.PredTSN)
edgelist_T.PreyTSN = parse.(Int64, edgelist_T.PreyTSN)
return edgelist_T
end