|
2 | 2 | #' |
3 | 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 | 4 | #' |
5 | | -#' @param DAT_mat a dataframe as returned by datsteps |
| 5 | +#' @param DAT_df a dataframe as returned by datsteps |
6 | 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 | 7 | #' |
8 | 8 | #' @return the same dataframe, with scaled 'weight'-values |
9 | 9 | #' |
10 | 10 | #' @export scaleweight |
11 | 11 |
|
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) |
14 | 14 | if (is.numeric(var)) { |
15 | | - uvar <- unique(DAT_mat[,var]) |
| 15 | + uvar <- unique(DAT_df[,var]) |
16 | 16 | 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]),] |
18 | 18 | 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) |
20 | 20 | } |
21 | 21 | } 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 |
24 | 24 | } |
25 | | - return(res_DAT_mat) |
| 25 | + return(res_DAT_df) |
26 | 26 | } |
0 commit comments