Skip to content

Commit e496ba6

Browse files
committed
again fix in generate.stepsize
1 parent 6eb6a7a commit e496ba6

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

R/datplot_utility.R

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
#'
33
#' @description todo
44
#'
5-
#' @param DAT_df todo
5+
#' @param DAT_mat todo
66
#'
77
#' @return stepsize
88
#'
99
#' @export generate.stepsize
1010

11-
generate.stepsize <- function(DAT_df) {
12-
timespans <- abs(DAT_df[,3] - DAT_df[,4])
11+
generate.stepsize <- function(DAT_mat) {
12+
timespans <- abs(DAT_mat[,3] - DAT_mat[,4])
13+
stepsize <- min(timespans)
1314
if(stepsize < 1) {
1415
stepsize <- 1
1516
}
@@ -22,16 +23,16 @@ generate.stepsize <- function(DAT_df) {
2223
#' @description Requires a dataframe with 4 variables: ID (ideally factor), group (ideally factor),
2324
#' minimum date (int/numeric) and maximum date (int/numeric).
2425
#'
25-
#' @param DAT_df a dataframe with 4 variable: ID, group, minimum date (int/num) maximum date (int/num)
26+
#' @param DAT_mat a dataframe with 4 variable: ID, group, minimum date (int/num) maximum date (int/num)
2627
#' @param DAT_err a vector containing the indizes of the dates which are in wrong order
2728
#'
28-
#' @return corrected DAT_df
29+
#' @return corrected DAT_mat
2930
#'
3031
#' @export switch.dating
3132

32-
switch.dating <- function(DAT_df, DAT_err) {
33-
DAT_df[DAT_err,3:4] <- DAT_df[DAT_err,4:3]
34-
return(DAT_df)
33+
switch.dating <- function(DAT_mat, DAT_err) {
34+
DAT_mat[DAT_err,3:4] <- DAT_mat[DAT_err,4:3]
35+
return(DAT_mat)
3536
}
3637

3738

@@ -76,46 +77,46 @@ get.weights <- function(DAT_min, DAT_max) {
7677
#' displayed as negative values while dates CE are positive values. Ignoring this will cause problems
7778
#' in any case.
7879
#'
79-
#' @param DAT_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.
80+
#' @param DAT_mat 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.
8081
#' @param stepsize defaults to 5. Number of years that should be used as an interval for creating dating steps.
8182
#'
8283
#' @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)
8384
#'
8485
#' @export create.sub.objects
8586

86-
create.sub.objects <- function(DAT_df, stepsize) {
87+
create.sub.objects <- function(DAT_mat, stepsize) {
8788

88-
mean_year_index <- which(DAT_df[,4]-DAT_df[,3] < stepsize)
89+
mean_year_index <- which(DAT_mat[,4]-DAT_mat[,3] < stepsize)
8990

9091
if (length(mean_year_index) == 0) {
91-
outputnr <- ceiling(sum(((abs(DAT_df[,3]-DAT_df[,4]))/stepsize)+1))
92+
outputnr <- ceiling(sum(((abs(DAT_mat[,3]-DAT_mat[,4]))/stepsize)+1))
9293
} else {
93-
outputnr <- ceiling(sum(((abs(DAT_df[-mean_year_index,3]-DAT_df[-mean_year_index,4]))/stepsize)+1))
94+
outputnr <- ceiling(sum(((abs(DAT_mat[-mean_year_index,3]-DAT_mat[-mean_year_index,4]))/stepsize)+1))
9495
outputnr <- outputnr+length(mean_year_index)
9596
}
9697

97-
result <- as.data.frame(matrix(ncol = ncol(DAT_df)+1, nrow = outputnr+100))
98+
result <- as.data.frame(matrix(ncol = ncol(DAT_mat)+1, nrow = outputnr+100))
9899

99-
colnames(result) <- c(colnames(DAT_df), "DAT_step")
100-
diffs <- DAT_df[,4]-DAT_df[,3]
100+
colnames(result) <- c(colnames(DAT_mat), "DAT_step")
101+
diffs <- DAT_mat[,4]-DAT_mat[,3]
101102

102103
if (any(diffs < stepsize)) {
103104
diffs <- diffs[diffs < stepsize]
104105
warning(paste("stepsize is larger than the range of the closest dated object: ",
105-
paste(DAT_df[which(diffs < stepsize),1], collapse = ", "), " (Index = ",
106+
paste(DAT_mat[which(diffs < stepsize),1], collapse = ", "), " (Index = ",
106107
paste(which(diffs < stepsize), collapse = ", "), "). Using mean as year.", sep = ""))
107108
}
108109

109-
for (i in 1:nrow(DAT_df)) {
110+
for (i in 1:nrow(DAT_mat)) {
110111
sequence <- NULL
111-
if ((DAT_df[i,4]-DAT_df[i,3]) < stepsize) {
112-
sequence <- (DAT_df[i,3]+DAT_df[i,4])/2
112+
if ((DAT_mat[i,4]-DAT_mat[i,3]) < stepsize) {
113+
sequence <- (DAT_mat[i,3]+DAT_mat[i,4])/2
113114
} else {
114-
sequence <- seq(DAT_df[i,3], DAT_df[i,4], by = stepsize)
115+
sequence <- seq(DAT_mat[i,3], DAT_mat[i,4], by = stepsize)
115116
}
116117
length <- length(sequence)
117118
for (step in sequence) {
118-
wip <- DAT_df[i,]
119+
wip <- DAT_mat[i,]
119120
wip$DAT_Step <- step
120121
wip$weight <- wip$weight / length(sequence)
121122
first_na <- match(NA, result$ID)

0 commit comments

Comments
 (0)