forked from GlobalEcologyFlinders/FosSahul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FosSahul_Data import.R
69 lines (45 loc) · 2.14 KB
/
FosSahul_Data import.R
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
#-------------------------------------------------------------
# Data import for biodiversity metrics calculations using FosSahul2.0 database
#
#
# by Katharina J. Peters1, Frédérik Saltré, Tobias Friedrich, Zenobia Jacobs, Rachel Wood, Matthew McDowell, Sean Ulm and Corey, J. A. Bradshaw
#-------------------------------------------------------------
#SET YOUR WORKING DIRECTORY
library(dplyr)
library(tm)
#read in FosSahul database
FosSahul <- read.csv(file="~/FosSahul2.0.csv")
FosSahul[ FosSahul == "na" ] <- NA
#remove empty columns at bottom
FosSahul = FosSahul[!is.na(FosSahul$ID), ]
#-----------------------------------------------------------------------------------
#calibrate radiocarbon ages
CalC14D <- read.csv(file="~/CalibratedC14Dates_FosSahul.csv")
#delete NAs
CalC14D = na.omit(CalC14D)
#delete date ranges
FosSahul <- FosSahul[!grepl("null", FosSahul$AgeType, ignore.case = T) &
!grepl("range", FosSahul$AgeType, ignore.case = T),]
#change age in original dataset to years insteadt of ka
FosSahul$Age = as.numeric(as.character(FosSahul$Age))
FosSahul$Age = (1000 * FosSahul$Age)
FosSahul$Precision = as.numeric(as.character(FosSahul$Precision))
FosSahul$Precision = (1000 * FosSahul$Precision)
FosSahul$ID = as.factor(FosSahul$ID)
CalC14D$ID = as.factor(CalC14D$ID)
str(FosSahul)
str(CalC14D)
#Merge with original dataset
FosSahul =left_join(FosSahul, CalC14D, by = "ID")
#joining original ages and calibrated ages (for C14)
FosSahul$Age.calibrated = ifelse(grepl("Radiocarbon", FosSahul$DatingTechnique, ignore.case = TRUE), FosSahul$Age_cal, FosSahul$Age)
#same for precision
FosSahul$Precision.calibrated = ifelse(grepl("Radiocarbon", FosSahul$DatingTechnique, ignore.case = TRUE), FosSahul$Precision.y, FosSahul$Precision.x)
#delete now redundant factors
FosSahul$Age <- NULL
FosSahul$Age_cal <- NULL
FosSahul$Precision.x <- NULL
FosSahul$Precision.y <- NULL
#-----------------------------------------------------------------------------------------------------------
#create dataset with only A and A* rating
FS_QR = FosSahul[grepl("A", FosSahul$Quality, ignore.case = T),] #exclude dates below A quality