-
Notifications
You must be signed in to change notification settings - Fork 0
bindRows
Updated 17/10/2022
The repository is maintained by Thomas Spargo (thomas.spargo@kcl.ac.uk) - please reach out with any questions.
The bindRows function produces a matrix by combining a list of vectors or matrices with varying length/ncol, The final value/column of shorter list elements will be duplicated until max length/ncol is reached for all elements and rows can be bound.
#Define the variant characteristics using varChars function
var.Char<- varChars(f=0.75,g=0,numsteps=10,onsetRateDiff=1)
#Short lapply of genFamily for two small example population groups. One group with, and one without, variant
aTime <- lapply(0:5,genFamily,group="var",var.Char=var.Char)
bTime <- lapply(0:5,genFamily,group="novar",var.Char=var.Char)
#Combine list elements for each of aTime and bTime with bindRows (vector combining)
#Use base R cbind function to append a first column flagging the different populations
aBound<- cbind("var",bindRows(aTime))
bBound<- cbind("novar",bindRows(bTime))
#Combine aBound and bBound with bindRows (matrix combining)
allBound<- bindRows(list(aBound,bBound),isMatrix = TRUE)
x - A list of vectors or matrices.
isMatrix - Logical defaults to FALSE. Specify TRUE if x is a list of matrices. If FALSE, assumes a list of vectors as input.
silent - Logical, defaults to FALSE. Specify TRUE to silence warning about dropping of NULL list elements
Input vectors or matrices which need to be bound together rowwise. The final element (if vector) or column (if matrix) of shorter list elements are duplicated until all elements have equal length/ncol and rows can be bound.
This approach is taken because families generated by genFamily can have a different number of sampling points until the max lifetime risk is reached for all family members, producing vectors of differing lengths. bindRows allows these differing families to be combined, since the 'max' lifetime risk in families with fewer sampling points remains 'max' across all time points.
Any NULL elements in the input list will be dropped; a warning will indicate when this occurs, unless silent=TRUE.
A single matrix combining all elements of the input list, bound rowwise. The final element (if vector) or column (if matrix) of shorter list elements are duplicated until all elements have equal length/ncol and rows can be bound.