You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: R/datplot_funs.R
+82-23Lines changed: 82 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -5,38 +5,76 @@
5
5
#' displayed as negative values while dates CE are positive values. Ignoring this will cause problems
6
6
#' in any case.
7
7
#'
8
-
#' @param df a dataframe with 4 variable: ID, group, minimum date (int/num) maximum date (int/num), _must_ be in this order, colnames are irrelevant; each object _must_ be one row.
8
+
#' @param df a dataframe with 4 variables: ID, group, minimum date (int/num) maximum date (int/num), _must_ be in this order, colnames are irrelevant; each object _must_ be one row.
9
9
#' @param stepsize defaults to 5. Number of years that should be used as an interval for creating dating steps.
10
10
#'
11
11
#' @return a larger dataframe with a number of steps for each object as well as a 'weight' value, that is a quantification of how well the object is dated (lesser value means object is dated to larger timespans, i.e. with less confidence)
12
12
#'
13
13
#' @export datsteps
14
14
15
-
datsteps<-function(df, stepsize=5) {
15
+
datsteps<-function(df, stepsize=25) {
16
16
result<- as.data.frame(NULL)
17
-
if (any(df[,3] >df[,4]) ==TRUE) {
18
-
print(paste("Error: Dating seems to be in wrong order at ",
19
-
df[which(df[,3] >df[,4]),1],
20
-
" (Index: ", which(df[,3] >df[,4]), ")",
21
-
". Please supply minimum date in 3rd Column, maximum date in 4th.", sep=""))
22
-
} else {
23
-
weights<- get.weights(df[,3], df[,4])
17
+
if (stepsize=="auto") {
18
+
timespans<- abs(df[,3] -df[,4])
19
+
stepsize<- generate.stepsize(timespans)
20
+
} elseif (!is.numeric(stepsize)) {
21
+
stop(error("stepsize has to be either 'auto' or numeric."))
22
+
}
24
23
24
+
if (any(df[,3] >df[,4])) {
25
+
warning(paste("Warning: Dating seems to be in wrong order at ID ", paste(df[which(df[,3] >df[,4]),1], collapse=", "), " (Index: ",
26
+
paste(which(df[,3] >df[,4]), collapse=", "), ")",
27
+
". Dates have been switched, but be sure to check your original data for possible mistakes.", sep=""))
28
+
DAT_err<- which(df[,3] >df[,4])
29
+
df<-switch.dating(df, DAT_err)
30
+
}
25
31
26
-
if (any(weights[,2] ==FALSE)) {
27
-
print(paste("Warning: DAT_min and DAT_max in ",
28
-
df[which(weights==FALSE),1],
29
-
" (Index: ", which(weights==FALSE), ")",
30
-
" have the same value! Is this correct? Please check the table for possible errors.", sep=""))
31
-
}
32
+
weights<- get.weights(df[,3], df[,4])
32
33
33
-
df$weight<-weights[,1]
34
-
result<- create.sub.objects(df, stepsize)
35
-
}
34
+
df$weight<-weights[,1]
35
+
result<- create.sub.objects(df, stepsize)
36
36
return(result)
37
37
}
38
38
39
39
40
+
#' Generate stepsize
41
+
#'
42
+
#' Requires a dataframe with 4 variables: ID (ideally factor), group (ideally factor),
43
+
#' minimum date (int/numeric) and maximum date (int/numeric).
44
+
#'
45
+
#' @param df a dataframe with 4 variable: ID, group, minimum date (int/num) maximum date (int/num)
0 commit comments