-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindexregionfunc2.R
More file actions
29 lines (29 loc) · 824 Bytes
/
indexregionfunc2.R
File metadata and controls
29 lines (29 loc) · 824 Bytes
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
function (indexlist, subset, beta, indexmethod = c("mean", "median",
"tbrm"))
{
nr = length(indexlist$PID)
temp2 = matrix(NA, nrow = nr, ncol = ncol(beta))
rownames(temp2) = names(indexlist$SID)
colnames(temp2) = colnames(beta)
for (i in 1:nr) {
var = indexlist$PID[[i]][indexlist$PID[[i]] %in% subset]
temp = beta[var, ]
if (length(var == 0)) {
temp2[i, ] = NA
}
if (length(var == 1)) {
temp2[i, ] = temp
}
else {
if (indexmethod == "tbrm") {
temp2[i, ] = apply(temp, 2, eval(indexmethod))
}
else {
temp2[i, ] = apply(temp, 2, eval(indexmethod),
na.rm = TRUE)
}
}
}
temp2=temp2[!is.na(temp2[,1])]
return(temp2)
}