forked from GlobalEcologyFlinders/FosSahul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FosSahul_Rating_updated_March2021.R
763 lines (582 loc) · 35.7 KB
/
FosSahul_Rating_updated_March2021.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
#-------------------------------------------------------------
# Quality rating function for 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
#-------------------------------------------------------------
library(dplyr)
#SET YOUR WORKING DIRECTORY
#load csv file of FosSahul database
FosSahul <- read.csv(file="~/FosSahul2.0.csv") #read in the datafile in .csv format
FosSahul <- read.csv(file.choose()) #read in the datafile in .csv format
FosSahul[is.na(FosSahul)] <- 'na' #replaces all the missing data with "na"to avoid TRUE/FALSE errors
FosSahul$C14_CNRatioValue <-as.numeric(as.character(FosSahul$C14_CNRatioValue)) #makes CNRatioValue nurmeric
FosSahul$C14_CNRatioValue[is.na(FosSahul$C14_CNRatioValue)] <- '0' #replaces missing data for CNRatioValue with 0
FosSahul$C14_NPercentage <-as.numeric(as.character(FosSahul$C14_NPercentage)) #makes NPercentage nurmeric
FosSahul$C14_NPercentage[is.na(FosSahul$C14_NPercentage)] <- '0' #replaces missing data for NPercentage with 0
FosSahulQR <- function(x) {
preQuality <- character(nrow(x))
Reason <- character(nrow(x))
for (i in 1:nrow(x)) {
a <- x[i, ]
# If there is no lab code
if (a$AgeID == "?"|
a$AgeID =="na" |
a$AgeID =="not reported" |
a$AgeID =="Not given") {
preQuality[i] <- "C"
Reason[i] <- "Missing lab code"
}
# If the dating technique is not known
else if (a$DatingTechnique == "na") {
preQuality[i] <- "C"
Reason[i] <- "Dating technique unknown"
}
# If it is an age range or presence only data
else if (a$AgeType == "range") {
preQuality[i] <- "C"
Reason[i] <- "Date range"
}
else if (a$AgeType == "presence") {
preQuality[i] <- "C"
Reason[i] <- "Presence only"
}
# If it is a radiocarbon age
else if (grepl("Radiocarbon", a$DatingTechnique)) {
# If dating was made on a mixture of bones
if (grepl("mixed bones", a$DatedMaterial, ignore.case = TRUE) |
grepl("mixed bones", a$DatedRemain, ignore.case = TRUE) |
grepl("bulk bones", a$DatedMaterial, ignore.case = TRUE) |
grepl("bulk bones", a$DatedRemain, ignore.case = TRUE) ) {
preQuality[i] <- "C"
Reason[i] <- "Mixed/bulk bones were dated"
}
# If bulk soil organics were dated
else if (grepl("bulk soil organic", a$DatedMaterial, ignore.case = TRUE) |
grepl("bulk soil organic", a$DatedRemain, ignore.case = TRUE)) {
preQuality[i] <- "C"
Reason[i] <- "Bulk soil organics were dated"
}
# If inorganic calcite was dated
else if (grepl("Speleothem", a$DatedMaterial, ignore.case = TRUE) |
grepl("Speleothem", a$DatedRemain, ignore.case = TRUE) |
grepl("Flowstone", a$DatedRemain, ignore.case = TRUE) |
a$DatedRemain == "Sediment" &
a$DatedMaterial == "Carbonate") {
preQuality[i] <- "C"
Reason[i] <- "Inorganic calcite dated"
}
# If bone or teeth were dated
else if (grepl("Bone", a$DatedRemain, ignore.case = TRUE) |
grepl("Tooth", a$DatedRemain, ignore.case = TRUE) |
grepl("Teeth", a$DatedRemain, ignore.case = TRUE)) {
# If single aminoacid was dated
if (a$DatedMaterial == "Single aminoacid") {
# If extraction problems were reported
if (a$C14_ExtractionProblem == "Yes") {
preQuality[i] <- "B"
Reason[i] <- "Reported extraction problems"
}
#if pretreatment was adequate
else if (grepl("XAD-2", a$C14_Pretreatment, ignore.case = TRUE) |
grepl("Ninhydrin", a$C14_Pretreatment, ignore.case = TRUE) |
grepl("ultrafiltration", a$C14_Pretreatment, ignore.case = TRUE) |
grepl("C-AF", a$C14_Pretreatment, ignore.case = TRUE)) {
preQuality[i] <- "m*"
Reason[i] <- "Individual aminoacids dated with adequate pretreatment"
}
else {
preQuality[i] <- "B"
Reason[i] <- "Inadequate pretreatment"
}
}
# If collagen was dated
else if (a$DatedMaterial == "Collagen") {
# If extraction problems were reported
if (a$C14_ExtractionProblem == "Yes") {
preQuality[i] <- "B"
Reason[i] <- "Reported problems with collagen extraction"
}
# If collagen preservation is unknown
else if (a$C14_CNRatioValue == "Not reported" |
a$C14_CNRatioValue == "na") {
preQuality[i] <- "B"
Reason[i] <- "Unknown collagen preservation"
}
#if pretreatment was adequate
else if (grepl("XAD-2", a$C14_Pretreatment, ignore.case = TRUE) |
grepl("Ninhydrin", a$C14_Pretreatment, ignore.case = TRUE) |
grepl("ultrafiltration", a$C14_Pretreatment, ignore.case = TRUE) |
grepl("C-AF", a$C14_Pretreatment, ignore.case = TRUE)){
#if CN ratio was reported
if (a$C14_CNRatioValue>2 && a$C14_CNRatioValue <4) {
#if %N was reported
if (a$C14_NPercentage > 0){
preQuality[i] <- "m*"
Reason[i] <- "All requirements met"
}
else {
preQuality[i] <- "B"
Reason[i] <- "%N not reported"
}
}
else {
preQuality[i] <- "B"
Reason[i] <- "CN ratio not reported"
}
}
#if pretreatment is inadequate
else {
preQuality[i] <- "B"
Reason[i] <- paste("Pretreatment inadequate (", a$C14_Pretreatment, ")")
}
}#closes collagen section (radiocarbon)
# If tooth enamel was dated
else if (a$DatedMaterial == "Enamel") {
preQuality[i] <- "C"
Reason[i] <- "Tooth enamel was dated"
}
#If apatite was dated
else if (a$DatedMaterial == "Apatite") {
preQuality[i] <- "C"
Reason[i] <- "Bone apatite was dated"
}
# If bone was given as dated material but no further specification
else {
preQuality[i] <- "C"
Reason[i] <- "Inadequate material was dated"
}
}#closes bone and teeth section (radiocarbon)
#If wood or seeds were dated
else if (a$DatedRemain == "wood" |
a$DatedRemain == "seed") {
if (a$DatedMaterial == "alpha-cellulose") {
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else {
preQuality[i] <- "C"
Reason[i] <- "Unknown molecule used for dating"
}
}#closes woods and seeds section (radiocarbon)
#If eggshell was dated
else if (grepl("eggshell", a$DatedRemain, ignore.case = TRUE)) {
if (a$DatedMaterial == "Organic fraction") {
preQuality[i] <- "C"
Reason[i] <- "Organic fraction was dated"
}
else if (a$DatedMaterial == "Carbonate") {
if (a$C14_Pretreatment == "Grinding and acid etching") {
preQuality[i] <- "m*"
Reason[i] <- "All requirements met"
}
else {
preQuality[i] <- "B"
Reason[i] <- paste("Inadequate pretreatment to remove seconday carbonate (", a$C14_Pretreatment, ")")
}
}
else {
preQuality[i] <- "C"
Reason[i] <- "Inappropriate material was dated using Radiocarbon dating"
}
}#closes eggshell section (radiocarbon)
#if shells were dated
else if (grepl("shell", a$DatedRemain, ignore.case = TRUE) |
grepl("coral", a$DatedRemain, ignore.case = TRUE) |
grepl("otolith", a$DatedRemain, ignore.case = TRUE) |
grepl("shell", a$DatedMaterial, ignore.case = TRUE) |
grepl("coral", a$DatedMaterial, ignore.case = TRUE) |
grepl("otolith", a$DatedMaterial, ignore.case = TRUE)){
if (grepl("carbonate", a$DatedMaterial, ignore.case = TRUE)) {
if (a$C14_Pretreatment == "Physical cleaning and acid etching") {
if(a$C14_corals/shells_X-ray_diffraction_recrystallisation == "yes") {
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else {
preQuality[i] <- "B"
Reason[i] <- "Shell, coral or otolith was dated without X-ray_diffraction"
}
}
else {
preQuality[i] <- "B"
Reason[i] <- paste("Shell, coral or otolith carbonate was dated with insufficient pretreatment:", a$C14_Pretreatment)
}
}
else {
preQuality[i] <- "B"
Reason[i] <- "Shell, coral or otolith was dated without further specification"
}
}#closes shell section (radiocarbon)
#if gut contents of coprolites were dated
else if (grepl("gut contents", a$DatedRemain, ignore.case = TRUE) |
grepl("coprolite", a$DatedRemain, ignore.case = TRUE)) {
if (a$DatedMaterial == "alpha-cellulose") {
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else {
preQuality[i] <- "C"
Reason[i] <- "Unknown molecule used for dating"
}
}#closes gut content and coprolite section
#If charcoal was dated
else if (grepl("Charcoal", a$DatedMaterial, ignore.case = TRUE)) {
#If no info about pretreatment is given
if (a$C14_Pretreatment == "Not reported" |
a$C14_Pretreatment == "not reported" |
a$C14_Pretreatment == "na"){
preQuality[i] <- "C"
Reason[i] <- "Missing info about pretreatment"
}
else if (grepl("ABOX", a$C14_Pretreatment, ignore.case = TRUE) |
grepl("chlorate oxidation", a$C14_Pretreatment, ignore.case = TRUE)) {
preQuality[i] <- "m"
Reason[i] <- "Adequate pretreatment"
}
else {
preQuality[i] <- "B"
Reason[i] <- paste("Pretreatment inadequate (", a$C14_Pretreatment, ")")
}
}#closes charcoal section (radiocarbon)
# If no info about dated molecule was provided
else if (a$DatedMaterial == "Not reported" |
a$DatedMaterial == "") {
preQuality[i] <- "C"
Reason[i] <- "No info about dated molecule"
}
# If anything else was dated
else {
preQuality[i] <- "C"
Reason[i] <- "Inappropriate material was dated using Radiocarbon dating"
}
} #closes radiocarbon section
#if it is an AAR age
else if (grepl("AAR", a$DatingTechnique)) {
#if bone or tooth was dated
if (#grepl("bone", a$DatedMaterial, ignore.case = TRUE) |
grepl("bone", a$DatedRemain, ignore.case = TRUE) |
#grepl("tooth", a$DatedMaterial, ignore.case = TRUE) |
grepl("tooth", a$DatedRemain, ignore.case = TRUE) |
#grepl("teeth", a$DatedMaterial, ignore.case = TRUE) |
grepl("teeth", a$DatedRemain, ignore.case = TRUE)) {
preQuality[i] <- "C"
Reason[i] <- "Bone or teeth were dated using AAR"
}
else if (grepl("eggshell", a$DatedRemain, ignore.case = TRUE) |
grepl("otolith", a$DatedRemain, ignore.case = TRUE)){
if(grepl("burnt", a$AAR_thermal_history, ignore.case = TRUE) |
grepl("unknown", a$AAR_thermal_history, ignore.case = TRUE)) {
preQuality[i] <- "C"
Reason[i] <- paste("thermal history (", a$AAR_thermal_history, ")")
}
else if(grepl("yes", a$AAR_demonstrated_CS_behaviour, ignore.case = TRUE)){
if(grepl("yes", a$AAR_replication_with_low_uncertainty, ignore.case = TRUE)){
if(a$Association == "direct" | a$Association == "Direct"){
if(grepl("yes", a$AAR_reliable_calibration, ignore.case = TRUE)){
preQuality[i] <- "m*"
Reason[i] <- "All requirements met"
}
else{
preQuality[i] <- "m"
Reason[i] <- "No independent calibration"
}
}
else{
preQuality[i] <- "C"
Reason[i] <- "AAR indirect age"
}
}
else{
preQuality[i] <- "C"
Reason[i] <- "AAR unreplicated age"
}
}
else{
preQuality[i] <- "C"
Reason[i] <- "AAR on potential open system"
}
}#closes AAR eggshell/otholith section
}#closes AAR section
#if it is an uranium-series age
else if (grepl("U-TH", a$DatingTechnique, ignore.case = TRUE) |
grepl("Th/U", a$DatingTechnique, ignore.case = TRUE)) {
#if teeth were dated
if (grepl("teeth", a$DatedMaterial, ignore.case = TRUE) |
grepl("tooth", a$DatedMaterial, ignore.case = TRUE) |
grepl("teeth", a$DatedRemain, ignore.case = TRUE) |
grepl("tooth", a$DatedRemain, ignore.case = TRUE)){
if(grepl("ICP-MS", a$DatingTechnique, ignore.case = TRUE) |
grepl("TIMS", a$DatingTechnique, ignore.case = TRUE)) {
if(grepl("yes", a$Uth_ClosedSystem, ignore.case = TRUE)) {
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else{
preQuality[i] <- "B"
Reason[i] <- "Tooth was dated without demonstrated closed-system behaviour"
}
}
else{
preQuality[i] <- "C"
Reason[i] <- "Tooth was dated without appropriate method"
}
}#closes tooth section (U-series)
#if bone was dated
else if (grepl("bone", a$DatedMaterial, ignore.case = TRUE)){
if(grepl("ICP-MS", a$DatingTechnique, ignore.case = TRUE) |
grepl("TIMS", a$DatingTechnique, ignore.case = TRUE)) {
if(grepl("yes", a$Uth_ClosedSystem, ignore.case = TRUE)) {
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else{
preQuality[i] <- "B"
Reason[i] <- "Bone was dated without modelling"
}
}
else{
preQuality[i] <- "C"
Reason[i] <- "Bone was dated without further specification"
}
}#closes bone section (U-series)
#if eggshell was dated
else if (grepl("eggshell", a$DatedMaterial, ignore.case = TRUE)) {
#if ICP-MS or TIMS was used
if (grepl("TIMS", a$DatingTechnique, ignore.case = TRUE) |
grepl("ICP-MS", a$DatingTechnique, ignore.case = TRUE)) {
#if the pretreatment was adequate
if (a$Uth_Pretreatment == "Grinding and acid etching") {
preQuality[i] <- "m*"
Reason[i] <- "All requirements met"
}
# If no info about pretreatment is given
else if (a$Uth_Pretreatment == "Not reported" |
a$Uth_Pretreatment == "not reported" |
a$Uth_Pretreatment == "na" |
a$Uth_Pretreatment == "null"){
preQuality[i] <- "C"
Reason[i] <- "Missing info about pretreatment"
}
else {
preQuality[i] <- "C"
Reason[i] <- paste("Pretreatment inadequate (", a$Uth_Pretreatment, ")")
}
}
else {
preQuality[i] <- "C"
Reason[i] <- "Eggshell was dated without ICP-MS or TIMS"
}
}#closes eggshell section (U-series)
#if closed-system of no body remains were dated
else if (grepl("speleothem", a$DatedMaterial, ignore.case = TRUE) |
grepl("coral", a$DatedMaterial, ignore.case = TRUE) |
grepl("calcite", a$DatedMaterial, ignore.case = TRUE) |
grepl("speleothem", a$DatedRemain, ignore.case = TRUE) |
grepl("coral", a$DatedRemain, ignore.case = TRUE) |
grepl("calcite", a$DatedRemain, ignore.case = TRUE)){
#if ICP-MS or TIMS was used
if (grepl("TIMS", a$DatingTechnique, ignore.case = TRUE) |
grepl("ICP-MS", a$DatingTechnique, ignore.case = TRUE)) {
#if detrital correction was done
if (grepl("yes", a$Uth_DetritalCorrection, ignore.case = TRUE )){
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else {
preQuality[i] <- "C"
Reason[i] <- "Closed-system of no body remains were dated without detrital correction"
}
}
else {
preQuality[i] <- "C"
Reason[i] <- "Closed-system of no body remains were dated twithout ICP-MS or TIMS"
}
}#closes closed system of no body remains section (U-series)
else {
preQuality[i] <- "C"
Reason[i] <- "Uranium-series age on inadequate material"
}
} #closes U-series -section
#if it is an ESR age
else if (grepl("ESR", a$DatingTechnique, ignore.case = TRUE)){
#if enamel was dated
if (grepl("enamel", a$DatedMaterial, ignore.case = TRUE)){
#if it is combined ESR and closed-system U-series modelling
if (grepl("CSUS-ESR", a$DatingTechnique, ignore.case = TRUE)){
preQuality[i] <- "m*"
Reason[i] <- "All requirements met"
}
#if EU and LU ages are model dependant with a p-value derived fro a U-series estimate
else if (a$DatingTechnique =="US-ESR"){
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else if (a$ESR_InternalDoseRate.10.. == "yes") {
if (a$ESR_GammaDoseRate == "in situ") {
preQuality[i] <- "m*"
Reason[i] <- "All requirements met"
}
else if (a$ESR_GammaDoseRate == "assumed") {
preQuality[i] <- "m"
Reason[i] <- "Gamma dose rate assumed"
}
else {
preQuality[i] <- "C"
Reason[i] <- "No information on gamma dose rate"
}
}
else if (a$ESR_InternalDoseRate.10.. == "no") {
preQuality[i] <- "B"
Reason[i] <- "Internal dose rate > 10% of total dose rate"
}
else {
preQuality[i] <- "B"
Reason[i] <- "Internal dose rate not given, no U-series constraint on possible history of U-uptake"
}
}#closes enamel section (ESR)
else {
preQuality[i] <- "C"
Reason[i] <- "Material other than tooth enamel was dated using ESR"
}
}#closes ESR section
#if it is an luminescence (Luminescence dating) or thermoluminescence (TL) age
else if (grepl("OSL", a$DatingTechnique, ignore.case = TRUE) |
grepl("TL", a$DatingTechnique, ignore.case = TRUE)) {
#if organic material was dated
if (grepl("bone", a$DatedMaterial, ignore.case = TRUE) |
grepl("tooth", a$DatedMaterial, ignore.case = TRUE) |
grepl("teeth", a$DatedMaterial, ignore.case = TRUE) |
grepl("eggshell", a$DatedMaterial, ignore.case = TRUE)) {
preQuality[i] <- "C"
Reason[i] <- "Organic material was dated using luminescence"
}
#if sediment was dated
if (grepl("sediment", a$DatedRemain, ignore.case = TRUE)) {
if (grepl("single grain", a$Luminescence_EquivalentDoseMeasurement, ignore.case = TRUE)) {
if(grepl("adequately", a$Luminescence_BleachingStatus, ignore.case = TRUE) |
grepl("partially", a$Luminescence_BleachingStatus, ignore.case = TRUE)) {
if(grepl("yes", a$LuminescenceSingleGrain_EquivalentDoseModel, ignore.case = TRUE)) {
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else if(grepl("adequately", a$Luminescence_BleachingStatus, ignore.case = TRUE)) {
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else{
preQuality[i] <- "C"
Reason[i] <- "Single-grain OSL age that cannot be modelled"
}
}
else {
preQuality[i] <- "C"
Reason[i] <- "Single-grain OSL age that is not sufficiently bleached"
}
}#closes Luminescence dating single-grain section
else if(grepl("single aliquot", a$Luminescence_EquivalentDoseMeasurement, ignore.case = TRUE) |
grepl("multi aliquot", a$Luminescence_EquivalentDoseMeasurement, ignore.case = TRUE)) {
if(grepl("adequately", a$Luminescence_BleachingStatus, ignore.case = TRUE)){
preQuality[i] <- "m"
Reason[i] <- "All requirements met"
}
else{
preQuality[i] <- "C"
Reason[i] <- "Age for mixed or partially bleached sediment"
}
}#closes multi-grain section (Luminescence dating)
if (grepl("na", a$Luminescence_EquivalentDoseMeasurement, ignore.case = TRUE)) {
preQuality[i] <- "C"
Reason[i] <- "Luminescence dating method not specified"
}
}#closes sediment secion (Luminescence dating)
else{
preQuality[i] <- "C"
Reason[i] <- "Inappropriate material dated using Luminescence dating"
}
}#closes Luminescence dating section
} ### closes for loop
result <- data.frame(Species = x$Species, AgeID = x$AgeID, Association =x$Association, Association.sub.category =x$Association.sub.category, preQuality = preQuality, Reason = Reason)
} ### closes function
new.data<-FosSahulQR(FosSahul) #runs function
#This is the Endrating function which does the second rating step
EndRating<- function(x) {
#preQuality <- character(nrow(x))
Quality <- character(nrow(x))
QualityReason <- character(nrow(x))
for (i in 1:nrow(x)) {
a <- x[i, ]
if(a$preQuality =="m*"){
if(a$Association =="Direct" | a$Association =="direct"){
Quality[i] <- "A*"
QualityReason[i] <- "Direct age"
}
else if(a$Association =="Indirect" | a$Association =="indirect"){
if (a$Association.sub.category == "Yes" | a$Association.sub.category == "yes"){
Quality[i] <- "A"
QualityReason[i] <- "Indirect age"
}
else if(a$Association.sub.category == "Uncertain" | a$Association.sub.category == "uncertain"){
Quality[i] <- "B"
QualityReason[i] <- "Uncertain stratographical association"
}
else if(a$Association.sub.category == "No" | a$Association.sub.category == "no"){
Quality[i] <- "C"
QualityReason[i] <- "No stratographical association"
}
else {
Quality[i] <- "NA"
QualityReason[i] <- "Association sub category not clear"
}
}
else {
Quality[i] <- "NA"
QualityReason[i] <- "Not clear if age is direct or indirect"
}
}
else if (a$preQuality =="m"){
if(a$Association =="Direct" | a$Association =="direct"){
Quality[i] <- "A"
QualityReason[i] <- "Direct age"
}
else if (a$Association =="Indirect" | a$Association =="indirect"){
if (a$Association.sub.category == "Yes" | a$Association.sub.category == "yes"){
Quality[i] <- "A"
QualityReason[i] <- "Indirect age"
}
else if(a$Association.sub.category == "Uncertain" | a$Association.sub.category == "uncertain"){
Quality[i] <- "B"
QualityReason[i] <- "Uncertain stratographical association"
}
else if(a$Association.sub.category == "No" | a$Association.sub.category == "no"){
Quality[i] <- "C"
QualityReason[i] <- "No stratographical association"
}
else {
Quality[i] <- "NA"
QualityReason[i] <- "Association sub category not clear"
}
}
}
else if (a$preQuality =="B"){
Quality[i] <- "B"
# QualityReason[i] <- paste(a$Reason)
}
else if (a$preQuality =="C"){
Quality[i] <- "C"
QualityReason[i] <- paste(a$Reason)
}
else {
Quality[i] <- "NA"
QualityReason[i] <- paste(a$Reason)
}
}#closes for loop
rating <- data.frame(Species = x$Species, AgeID = x$AgeID, Reason = x$Reason, preQuality = x$preQuality, Association =x$Association, Association.sub.category =x$Association.sub.category, Quality = Quality, QualityReason = QualityReason)
}
Rated <- EndRating(new.data)
#adds the category collumn from result dataframe (Rated) to the original (FosSahul)
FosSahul$preQuality<-Rated$preQuality
FosSahul$Reason<-Rated$Reason
FosSahul$Quality<-Rated$Quality
FosSahul$QualityReason<-Rated$QualityReason
write.csv(FosSahul, "FosSahul_correction-rated.csv", row.names=FALSE) #saves the rated database as a csv. file