Hello,
Try the following.
res <- lapply(foo, function(x) if(x[1] == 1 ) x )
res[!sapply(res, is.null)]
Hope this helps,
Rui Barradas
Em 12-07-2014 14:25, ce escreveu:
Dear all,
I have a list of arrays :
foo<-list(A = c(1,3), B =c(1, 2), C = c(3, 1))
foo
$A
[1] 1 3
$B
[1] 1 2
$C
[1] 3 1
if( foo$C[1] == 1 ) foo$C[1]
lapply(foo, function(x) if(x[1] == 1 ) x )
$A
[1] 1 3
$B
[1] 1 2
$C
NULL
I don't want to list $C NULL in the output. How I can do that ?
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.