Re: [R] lapply returns NULL ?

2014-07-12 Thread luke-tierney
; , "ce" , r-help@r-project.org Subject: Re: [R] lapply returns NULL ? I think that removing them is something the OP doesn't understand how to do. The lapply function ALWAYS produces an output element for every input element. If this is not what you want then you need to choose

Re: [R] lapply returns NULL ?

2014-07-12 Thread ce
Thanks Jeff et. all, This is exactly what I needed. -Original Message- From: "Jeff Newmiller" [jdnew...@dcn.davis.ca.us] Date: 07/12/2014 10:38 AM To: "Uwe Ligges" , "ce" , r-help@r-project.org Subject: Re: [R] lapply returns NULL ? I think that rem

Re: [R] lapply returns NULL ?

2014-07-12 Thread Jeff Newmiller
I think that removing them is something the OP doesn't understand how to do. The lapply function ALWAYS produces an output element for every input element. If this is not what you want then you need to choose a looping structure that is not so tightly linked to the input, such as a for loop (unt

Re: [R] lapply returns NULL ?

2014-07-12 Thread Rui Barradas
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

Re: [R] lapply returns NULL ?

2014-07-12 Thread Uwe Ligges
On 12.07.2014 15:25, ce wrote: 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 lis

[R] lapply returns NULL ?

2014-07-12 Thread ce
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