Skip to content

Commit 9fab1d9

Browse files
committed
new sequence function prototype
1 parent 0ec558f commit 9fab1d9

4 files changed

Lines changed: 86 additions & 7 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export(calculate.outputrows)
44
export(create.sub.objects)
55
export(datsteps)
66
export(generate.stepsize)
7+
export(get.step.sequence)
78
export(get.weights)
89
export(scaleweight)
910
export(switch.dating)

R/datplot_utility.R

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,65 @@ calculate.outputrows <- function(DAT_mat, stepsize) {
9494
return(outputrows)
9595
}
9696

97+
98+
99+
100+
#' @title Calculate the sequence of dating steps
101+
#'
102+
#' @description approximation :( also i dont want to write documentation
103+
#'
104+
#' @param datmin todo
105+
#' @param datmax todo
106+
#' @param stepsize todo
107+
#'
108+
#' @return sequence
109+
#'
110+
#' @export get.step.sequence
111+
112+
get.step.sequence <- function(datmin = 0, datmax = 100, stepsize = 25) {
113+
timespan <- datmax - datmin
114+
if (timespan %/% stepsize == 0) {
115+
if (timespan > (stepsize*0.6)) {
116+
sequence <- c(datmin, round(((datmin+datmax)/2), digits = 0), datmax)
117+
print(sequence)
118+
} else {
119+
sequence <- c(datmin, datmax)
120+
print(sequence)
121+
}
122+
} else {
123+
sequence <- seq(from = datmin, to = datmax, by = stepsize)
124+
resid <- datmax-sequence[length(sequence)]
125+
print(paste("can fit ", timespan %/% stepsize, " times", sep = ""))
126+
print(paste("from: ", datmin, " to: ", datmax, sep=""))
127+
print(paste("there was a rest of ", resid))
128+
129+
if (resid >= (stepsize/2)) {
130+
print("and i resolved it this way:")
131+
stepsize_mod <- (datmax-datmin)/length(sequence)
132+
sequence <- round(seq(datmin, datmax, stepsize_mod), digits = 0)
133+
print(sequence)
134+
} else if (resid != 0) {
135+
print("sasad")
136+
move <- round(resid/(length(sequence)-1), digits = 0)
137+
sequence[2:length(sequence)] <- sequence[2:length(sequence)] + move
138+
sequence[length(sequence)] <- datmax
139+
print(sequence)
140+
} else {
141+
print("and i didnt resolve anything:")
142+
print(sequence)
143+
}
144+
}
145+
return(sequence)
146+
}
147+
148+
149+
150+
151+
152+
153+
154+
155+
97156
#' @title Create sub-objects for each object in a dataframe
98157
#'
99158
#' @description Requires a dataframe with 5 variables: ID (ideally factor), group (ideally factor),
@@ -124,11 +183,9 @@ create.sub.objects <- function(DAT_mat, stepsize) {
124183

125184
for (i in 1:nrow(DAT_mat)) {
126185
sequence <- NULL
127-
if ((DAT_mat[i,"datmax"]-DAT_mat[i,"datmin"]) < stepsize) {
128-
sequence <- (DAT_mat[i,"datmin"]+DAT_mat[i,"datmax"])/2
129-
} else {
130-
sequence <- seq(DAT_mat[i,"datmin"], DAT_mat[i,"datmax"], by = stepsize)
131-
}
186+
187+
sequence <- get.step.sequence(DAT_mat[i,"datmin"], DAT_mat[i,"datmax"], stepsize)
188+
132189
length <- length(sequence)
133190
for (step in sequence) {
134191
wip <- as.vector(DAT_mat[i,])

man/create.sub.objects.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get.step.sequence.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)