-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnamegetter.R
34 lines (28 loc) · 975 Bytes
/
namegetter.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
namegetter <- function(x){
## Namegetter
for (c in 1:dim(x)[2]){
q <- names(x)[grep(paste0("^Q",c,"."),names(x))[1]]
dq <- names(x)[grep(paste0("^DQ",c,"."),names(x))[1]]
if(!exists("qnames"))
{if(length(!is.na(q)) == 1) {qnames <- q}} else
{if(length(!is.na(q)) == 1) {qnames <- c(qnames,q)}}
if(!exists("dqnames"))
{if(length(!is.na(dq)) == 1) {dqnames <- dq}} else
{if(length(!is.na(dq)) == 1) {dqnames <- c(dqnames,dq)}}
}
qnames <- qnames[!is.na(qnames)]
dqnames <- dqnames[!is.na(dqnames)]
## Trim levels off names
for(i in 1:length(qnames)){
for (n in 1:nchar(qnames[i])){
if(substr(qnames[i],n,n) == "_") {qnames[i] <- substr(qnames[i],1,(n-1))}
}
}
for(i in 1:length(dqnames)){
for (n in 1:nchar(dqnames[i])){
if(substr(dqnames[i],n,n) == "_") {dqnames[i] <- substr(dqnames[i],1,(n-1))}
}
}
y <- list(qnames,dqnames)
return(y)
}