-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.existing.database.R
49 lines (43 loc) · 1.29 KB
/
query.existing.database.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
weights.modification <- function(data, gold, silver, bronze) {
weights <- c(gold, silver, bronze)
data$customscore <- apply(data[, c("Gold", "Silver", "Bronze")], 1,
function(row) sum(row * weights))
data <- data[order(data$customscore, decreasing = TRUE), ]
return(data)
}
exclude.people <- function(data, exc) {
for (i in 1:length(exc)) {
data <- data %>% filter((P1 != exc[i]) & (P2 != exc[i]) & (P3 != exc[i])
& (P4 != exc[i]) & (P5 != exc[i]))
}
return(data)
}
include.people <- function(data, inc) {
for (i in 1:length(inc)) {
data <- data %>% filter((P1 == inc[i]) | (P2 == inc[i]) | (P3 == inc[i])
| (P4 == inc[i]) | (P5 == inc[i]))
}
return(data)
}
get_IDs_for_names <- function(names, data){
x <- vector()
for (i in 1:length(names)) {
x[i] <- data$ID[data$FullName == names[i]]
}
return(x)
}
get_names_for_IDs <- function(id, data){
x <- vector()
for (i in 1:length(id)) {
x[i] <- data$FullName[data$ID == id[i]]
}
return(x)
}
get_names_for_IDs <- function(id, data){
x <- character(length(id))
for (i in seq_along(id)) {
match_index <- which(data$ID == id[i])
x[i] <- data$FullName[match_index[1]] # Use the first match if multiple
}
return(x)
}