Skip to content

Commit 28c2419

Browse files
committed
excluded scaleweight from utility file
1 parent b26045d commit 28c2419

2 files changed

Lines changed: 26 additions & 25 deletions

File tree

R/datplot_utility.R

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,4 @@ create.sub.objects <- function(DAT_mat, stepsize) {
147147
}
148148

149149

150-
#' @title Scales the content of the weight columns according to group membership
151-
#'
152-
#' @description Requires a dataframe as produced by datsteps(). (Meaning 6 columns in the following order: ID, group, minimum/earliest date, maximum/latest date, weight, 'DAT_Steps')
153-
#'
154-
#' @param DAT_mat a dataframe as returned by datsteps
155-
#' @param var the index of the column of said dataframe that should be used as the group variable, OR "all" (note: all non-numeric values will result in the weight being scaled accross all objects)
156-
#'
157-
#' @return the same dataframe, with scaled 'weight'-values
158-
#'
159-
#' @export scaleweight
160150

161-
scaleweight <- function(DAT_mat, var = c("all", 2) ) {
162-
res_DAT_mat <- data.frame(NULL)
163-
if (is.numeric(var)) {
164-
uvar <- unique(DAT_mat[,var])
165-
for (row in 1:length(uvar)) {
166-
wip <- DAT_mat[which(DAT_mat[,var] == uvar[row]),]
167-
wip$weight <- wip$weight / sum(wip$weight)
168-
res_DAT_mat <- rbind(res_DAT_mat, wip)
169-
}
170-
} else {
171-
DAT_mat$weight <- DAT_mat$weight / sum(DAT_mat$weight)
172-
res_DAT_mat <- DAT_mat
173-
}
174-
return(res_DAT_mat)
175-
}

R/scaleweights.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#' @title Scales the content of the weight columns according to group membership
2+
#'
3+
#' @description Requires a dataframe as produced by datsteps(). (Meaning 6 columns in the following order: ID, group, minimum/earliest date, maximum/latest date, weight, 'DAT_Steps')
4+
#'
5+
#' @param DAT_mat a dataframe as returned by datsteps
6+
#' @param var the index of the column of said dataframe that should be used as the group variable, OR "all" (note: all non-numeric values will result in the weight being scaled accross all objects)
7+
#'
8+
#' @return the same dataframe, with scaled 'weight'-values
9+
#'
10+
#' @export scaleweight
11+
12+
scaleweight <- function(DAT_mat, var = c("all", 2) ) {
13+
res_DAT_mat <- data.frame(NULL)
14+
if (is.numeric(var)) {
15+
uvar <- unique(DAT_mat[,var])
16+
for (row in 1:length(uvar)) {
17+
wip <- DAT_mat[which(DAT_mat[,var] == uvar[row]),]
18+
wip$weight <- wip$weight / sum(wip$weight)
19+
res_DAT_mat <- rbind(res_DAT_mat, wip)
20+
}
21+
} else {
22+
DAT_mat$weight <- DAT_mat$weight / sum(DAT_mat$weight)
23+
res_DAT_mat <- DAT_mat
24+
}
25+
return(res_DAT_mat)
26+
}

0 commit comments

Comments
 (0)