R/functions/TensorsGLMM.R

# Title     : TensorsGLMM.R
# Objective : Building tensors
# Created by: greyhypotheses
# Created on: 31/03/2022

#'
#' @param frame
#' @param field
#' @param FUN
#'
TensorsGLMM <- function (frame, field, FUN) {

  x <- lapply(X = frame[, field],  FUN = FUN)
  x <- dplyr::bind_cols(x)
  x[lower.tri(x, diag = FALSE)] <- NA
  x <- cbind(index = seq_len(nrow(x)), item = frame[, field], x)
  x <- rbind(c(0, 0, frame[, field]), x)
  colnames(x = x) <- c('index', field, seq_len(nrow(frame)))

  return(x)

}
premodelling/mixed documentation built on April 25, 2022, 6:27 a.m.