2.5 Subsetting criteria
Build vector indicating whether each observation is from a shipwreck:
isShipwreck <-
cleanAmphorae$Site_Name=="Cap del Vol" |
cleanAmphorae$Site_Name=="Ullastres I" |
cleanAmphorae$Site_Name=="Port-Vendres 4"
Workshops | Shipwrecks | |
---|---|---|
175 | 48 |
Build vectors indicating provenance group and whether observations are true outliers (IND, observations with no group assigned). Also, reformat “FabricGroup” and “ChemReferenceGroup”, so true outliers are singled out separately and not as a extra group.
ProvenanceGroup <- c()
isTrueIND <- c()
# coerce the original group variables (factors) into character vectors
# so we can use stringr package to operate on them.
cleanAmphorae$FabricGroup <-
as.character(cleanAmphorae$FabricGroup)
cleanAmphorae$ChemReferenceGroup <-
as.character(cleanAmphorae$ChemReferenceGroup)
for (i in 1:nrow(cleanAmphorae)){
groupChem <-
stringr::str_split(cleanAmphorae$ChemReferenceGroup[i], "-")[[1]]
groupFabric <-
stringr::str_split(cleanAmphorae$FabricGroup[i], "-")[[1]]
group <- ""
isATrueInd <- FALSE
if (groupChem[2] == "IND" || groupFabric[2] == "IND") {
group <- cleanAmphorae$ChemReferenceGroup[i]
if (!isShipwreck[i]) isATrueInd <- TRUE
index <- 1
for (j in 1:length(ProvenanceGroup)){
if (ProvenanceGroup[j] == paste(group, index, sep = ""))
index <- index + 1
}
group <- paste(group, index, sep = "")
cleanAmphorae$ChemReferenceGroup[i] <- group
cleanAmphorae$FabricGroup[i] <- group
}
else {
if (groupChem[1] == "ULL" ||
groupChem[1] == "PV4" ||
groupChem[1] == "CDV") {
group <- cleanAmphorae$ChemReferenceGroup[i]
}
else if (groupChem[1] == groupFabric[1]){
group <- groupChem[1]
}
}
ProvenanceGroup <- c(ProvenanceGroup, group[1])
isTrueIND <- c(isTrueIND, isATrueInd)
}
Assigned | Outliers | |
---|---|---|
205 | 18 |