You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Copyright (c) 2014-2017 Bryon Aragam. All rights reserved.
7
+
#
8
+
9
+
#
10
+
# PACKAGE CCDRALGORITHM: Helper methods for black/white lists
11
+
#
12
+
# CONTENTS:
13
+
# names_to_indices
14
+
# rows_to_list
15
+
# bwlist_check
16
+
# bwlist_to_weights
17
+
#
18
+
19
+
### Just a wrapper for match with a better name
20
+
names_to_indices<-function(v, names){
21
+
match(v, names)
22
+
} # END NAMES_TO_INDICES
23
+
24
+
### Returns a list whose components are the rows of a matrix
25
+
rows_to_list<-function(m){
26
+
lapply(1:nrow(m), function(j) m[j,])
27
+
} # END ROWS_TO_LIST
28
+
29
+
### Check correctness of input and transform from matrix to list of indices
30
+
bwlist_check<-function(bwlist, names){
31
+
## Consistency checks
32
+
if(!is.matrix(bwlist) || ncol(bwlist) !=2){
33
+
stop("Input must be a matrix with exactly 2 columns!")
34
+
}
35
+
36
+
if(any(is.na(bwlist))){
37
+
stop("Input cannot have missing values!")
38
+
}
39
+
40
+
### Convert characters names to indices
41
+
if(is.character(bwlist)){
42
+
bwlist<- as.vector(bwlist)
43
+
bwlist<- names_to_indices(bwlist, names)
44
+
bwlist<-matrix(bwlist, ncol=2)
45
+
}
46
+
47
+
storage.mode(bwlist) <-"integer"# This is important in ccdr_call to check overlap between blacklist and whitelist, fails if numerics are mixed with ints
48
+
rows_to_list(bwlist)
49
+
} # END BWLIST_CHECK
50
+
51
+
### Convert b/w lists to weight matrix of {-1,0,1}
52
+
# -1 = black listed (guaranteed to be absent / zero)
53
+
# 0 = white listed (guaranteed to be present / nonzero)
0 commit comments