从列表中消除所有具有NA作为结果的子列表元素

时间:2015-07-30 18:31:58

标签: r

如何从列表中删除所有具有NA作为结果的子列表元素?函数T的结果是组件列表。此列表包含导致具有长数字列表的子列表元素的元素,但是其他元素导致NA。

在更改之前进行总结的应用程序(PC和键盘开始表现异常)

z2p <- c(0.0279 , 0.0002, 0.0191, -0.0329,- 0.0002,- 0.0322, 0.0204, 0.0229, -0.0057, 0.0181, 0.0192, 0.0018, -0.0209, 0.0398, -0.0039, 0.0355, 0.0528, 0.0064, 0.0227, -0.0035, 0.0206, 0.0305, -0.0185, -0.0218, -0.0118, -0.0292, 0.0309, 0.0277, 0.0270, 0.0052, 0.0066, -0.0080,- 0.0066, 0.0002, 0.0006,- 0.0339, 0.0432,- 0.0115,- 0.0225,- 0.02,0.0118, 0.0151, 0.0011, 0.0162, 0.0020, 0.0306, -0.0222, -0.0255, 0.0464, 0.0155, 0.0020, -0.0235, 0.0094, 0.0154, -0.0251, 0.0229, 0.0464, 0.0158, -0.0085, 0.0146, -0.0283, 0.0492, 0.0084, 0.0262, -0.0223, 0.0389, 0.0092, -0.0032, -0.0178, -0.0308, -0.0208, -0.0131, -0.0155, 0.0031, 0.0273, -0.0154, 0.0501, -0.0253, 0.0392, 0.0821, -0.0092, -0.0097, 0.0195, 0.0522, -0.0466, -0.0309, -0.0038, 0.0365, 0.0448, 0.0193, 0.0403,- 0.0639, -0.0413, 0.0613, 0.0504, 0.0183, -0.0138, -0.0096, 0.0683, 0.0238, 0.0245, 0.0012, 0.0393, -0.0274, 0.0388, 0.0568, -0.0321, -0.0134, -0.0062, 0.0458, -0.0143, 0.0143, 0.0310, 0.0203, -0.0516 , 0.0572, 0.0470, -0.0403, 0.0649, 0.0285, -0.0215, 0.0766, -0.0650, -0.0302, 0.0705, -0.0459, 0.0265, 0.01193, -0.0050, -0.0827, -0.0016, -0.0312, 0.0088, 0.0264, 0.0478, 0.0337, 0.0638, -0.0058, 0.0530 , 0.01195,- 0.01114, 0.0207, 0.01018,- 0.0585,- 0.0115, 0.0069, 0.0071, 0.0546,- 0.0268, 0.01000,- 0.01081,- 0.0614, 0.01144,- 0.0466,- 0.0380, 0.0732, 0.0479, 0.0548, 0.0742,- 0.0776,- 0.0109, 0.01346, 0.0458, 0.0057, 0.0748,- 0.0523,- 0.0332,- 0.0295, 0.0072, 0.0002, 0.0448, 0.01245,- 0.0756,- 0.0402,- 0.0366, 0.0175,- 0.0313, 0.0153,- 0.0050,- 0.0128,- 0.0433, 0.0282, 0.0754, 0.0250, 0.0710, 0.01604,- 0.0151, 0.0355,- 0.0424, 0.01009,- 0.0858, 0.0531,- 0.0193,- 0.0364,- 0.0016,- 0.0613, 0.01312, 0.0920, 0.0150, 0.0327, 0.0802,- 0.0148, 0.0853, 0.0323, 0.0135, 0.01106, 0.0452,- 0.0565, 0.0118, 0.0919,-0.01297, 0.0996,0.0834)

# DYADIC  
ñ0<-z2p[((length(z2p) -64)+1):length(z2p)]
ñ1<-z2p[((length(z2p) -128)+1):length(z2p)]
ñ2<- z2p[((length(z2p) -256)+1):length(z2p)]
ñ3<- z2p[((length(z2p) -512)+1):length(z2p)]
z2p <- if( length(z2p) > 64 & length(z2p)  < 128 ){
ñ0
} else if( length(z2p) > 128 & length(z2p)  < 256 ){
ñ1
} else if(  length(z2p) > 256 & length(z2p)  < 512  ){
ñ2
} else if(  length(z2p) > 512 & length(z2p)  < 1024  ){
ñ3
}

# Demean.
library(Jmisc)
z3log <-demean(z2p)

# De – Trend (1 degree) + MA (0 degree) segments – Loess – Span Minimizes.

z4log <- as.vector(z3log-predict(loess(z3log~ seq(length(z3log)), model = FALSE,span = 0.25, degree = 2,parametric = FALSE, drop.square = FALSE, normalize = FALSE,family = c("gaussian"))))

library(EbayesThresh)    
prior =c("cauchy","laplace")
a <- c(0.05,0.1,0.15,0.2,0.25,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.70,0.75,0.80,0.85,0.9,0.95,1,1.25,1.3,1.35,1.4,1.45,1.50,1.55,1.6,1.65,1.7,1.75,1.8)
threshrule = c("median","mean","hard","soft","none")
ex <- expand.grid(prior=prior,a=a, threshrule= threshrule ,stringsAsFactors=FALSE)
T <- (mapply ( function(y,z,p) ebayesthresh (z4log, prior = y , a = z,   bayesfac = FALSE, sdev = NA,  verbose = FALSE, threshrule = p), ex$prior, ex$a, ex$threshrule))

由于这不是指列表中的项目,而是指列表中以NA为整个值的那些子列表,我找不到用NA作为值来消除子列表元素的方法。

1 个答案:

答案 0 :(得分:1)

我认为这就是全部:

T[!is.na(T)]