Skip to content
Permalink
Browse files

fix ifelse vector return issue

  • Loading branch information
nanxstats committed Nov 18, 2017
1 parent d2813dc commit 3f6e106c93ab9f28c532547f68b3cd9d5cc3d9b4
Showing with 9 additions and 25 deletions.
  1. +9 −25 R/desc-09-CTDD.R
@@ -45,7 +45,7 @@ extractCTDD = function(x) {

group1 = list(
'hydrophobicity' = c('R', 'K', 'E', 'D', 'Q', 'N'),
'normwaalsvolume' = c('G', 'A', 'S', 'T', 'P', 'D', 'C'),
'normwaalsvolume' = c('G', 'A', 'S', 'C', 'T', 'P', 'D'),
'polarity' = c('L', 'I', 'F', 'W', 'C', 'M', 'V', 'Y'),
'polarizability' = c('G', 'A', 'S', 'D', 'T'),
'charge' = c('K', 'R'),
@@ -72,7 +72,7 @@ extractCTDD = function(x) {
'solventaccess' = c('M', 'S', 'P', 'T', 'H', 'Y'))

xSplitted = strsplit(x, split = '')[[1]]
n = nchar(x)
n = nchar(x)

G = vector('list', 7)
for (i in 1:7) G[[i]] = rep(NA, n)
@@ -91,31 +91,15 @@ extractCTDD = function(x) {
for (i in 1:7) D[[i]] = matrix(ncol = 5, nrow = 3)

for (i in 1:7) {
for (j in 1:3) {
inds = which(G[[i]] == paste0('G', j))
quartiles = floor(length(inds) * c(0.25, 0.5, 0.75))

inds = which(G[[i]] == 'G1')
quartiles = floor(length(inds) * c(0.25, 0.5, 0.75))

D[[i]][1, ] = ifelse(
length(inds) > 0,
(inds[c(1, ifelse(quartiles > 0, quartiles, 1), length(inds))]) * 100/n,
0)

inds = which(G[[i]] == 'G2')
quartiles = floor(length(inds) * c(0.25, 0.5, 0.75))

D[[i]][2, ] = ifelse(
length(inds) > 0,
(inds[c(1, ifelse(quartiles > 0, quartiles, 1), length(inds))]) * 100/n,
0)

inds = which(G[[i]] == 'G3')
quartiles = floor(length(inds) * c(0.25, 0.5, 0.75))

D[[i]][3, ] = ifelse(
length(inds) > 0,
(inds[c(1, ifelse(quartiles > 0, quartiles, 1), length(inds))]) * 100/n,
0)
quartiles[which(quartiles <= 0)] = 1

D[[i]][j, ] = if (length(inds) > 0)
(inds[c(1, quartiles, length(inds))]) * 100/n else 0
}
}

D = do.call(rbind, D)

0 comments on commit 3f6e106

Please sign in to comment.
You can’t perform that action at this time.