Skip to content

Commit 0ec558f

Browse files
committed
processing df, not mat
1 parent 28c2419 commit 0ec558f

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

R/scaleweights.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
#'
33
#' @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')
44
#'
5-
#' @param DAT_mat a dataframe as returned by datsteps
5+
#' @param DAT_df a dataframe as returned by datsteps
66
#' @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)
77
#'
88
#' @return the same dataframe, with scaled 'weight'-values
99
#'
1010
#' @export scaleweight
1111

12-
scaleweight <- function(DAT_mat, var = c("all", 2) ) {
13-
res_DAT_mat <- data.frame(NULL)
12+
scaleweight <- function(DAT_df, var = c("all", 2) ) {
13+
res_DAT_df <- data.frame(NULL)
1414
if (is.numeric(var)) {
15-
uvar <- unique(DAT_mat[,var])
15+
uvar <- unique(DAT_df[,var])
1616
for (row in 1:length(uvar)) {
17-
wip <- DAT_mat[which(DAT_mat[,var] == uvar[row]),]
17+
wip <- DAT_df[which(DAT_df[,var] == uvar[row]),]
1818
wip$weight <- wip$weight / sum(wip$weight)
19-
res_DAT_mat <- rbind(res_DAT_mat, wip)
19+
res_DAT_df <- rbind(res_DAT_df, wip)
2020
}
2121
} else {
22-
DAT_mat$weight <- DAT_mat$weight / sum(DAT_mat$weight)
23-
res_DAT_mat <- DAT_mat
22+
DAT_df$weight <- DAT_df$weight / sum(DAT_mat$weight)
23+
res_DAT_df <- DAT_df
2424
}
25-
return(res_DAT_mat)
25+
return(res_DAT_df)
2626
}

0 commit comments

Comments
 (0)