nonAmbiguousMat
makes values of matrix 'mat' in col 'byCol' unique.
nonAmbiguousMat(
mat,
byCol,
uniqOnly = FALSE,
asList = FALSE,
nameMod = "amb_",
callFrom = NULL
)
sorted non-ambigous numeric vector (or list if 'asList'=TRUE and 'uniqOnly'=FALSE)
numeric or character matrix (or data.frame), column specified by 'byCol' must be/will be used as.numeric, 1st column of 'mat' will be considered like index & used for adding prefix 'nameMod' (unless byCol=1, then 2nd col will be used)
(character or integer-index) column by which ambiguousity will be tested
(logical) if =TRUE return unique only, if =FALSE return unique and single representative of non-unique values (with '' added to name), selection of representative of repeated: first (of sorted) or middle if >2 instances
(logical) return result as list
(character) prefix added to 1st column of 'mat' (expect 'by') for indicating non-unique/ambiguous values
(character) allow easier tracking of message(s) produced
for non-numeric use firstOfRepeated
- but 1000x much slower !; get1stOfRepeatedByCol
set.seed(2017); mat2 <- matrix(c(1:100,round(rnorm(200),2)),ncol=3,
dimnames=list(1:100,LETTERS[1:3]));
head(mat2U <- nonAmbiguousMat(mat2,by="B",na="_",uniqO=FALSE),n=15)
head(get1stOfRepeatedByCol(mat2,sortB="B",sortS="B"))
Run the code above in your browser using DataLab