R/transfer_Group.R

Defines functions transfer_Group

Documented in transfer_Group

#' @title  Transter function
#' 
#' @description 
#'  Transfer data to M groups of individuals
#' 
#' @param Data a numeric (quantitative) matrix or data frame
#' @param Group a vector of factors associated with group structure
#' @return list with the following results:
#' @return \item{Data.group}{original data}
#' @seealso \code{\link{split}}, \code{\link{iris}} 
#' @keywords internal
transfer_Group = function(Data, Group){
   
 if (is.data.frame(Data) == TRUE) {
     Data = as.matrix(Data)
   }
  
  
  rownames(Data) = Group                 #---- rownames of data=groups
  M = length(levels(Group))
  P = dim(Data)[2]
  n = as.vector(table(Group))
  N = sum(n)
  
  #============================================================================
  #  	       	                          output
  #============================================================================
  Data.group=list()
  
  #============================================================================
  #					                          split data
  #============================================================================
  Xm = split(Data, Group)  #Split Data
  grouprname = split(rownames(Data), Group)
  
  for(m in 1:M){  # dataset in form of matrix
    
    #if(class(Xm[[m]])!="data.frame"){
      Xm[[m]] = matrix(Xm[[m]], ncol=P)
      #}
    colnames(Xm[[m]]) = colnames(Data)
    rownames(Xm[[m]]) = grouprname[[m]]
  }
  
  
  Data.group=Xm
  
  
  return(Data.group)
}

Try the multigroup package in your browser

Any scripts or data that you put into this service are public.

multigroup documentation built on March 26, 2020, 5:50 p.m.