[R] NA and Character(0) in List Element

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Tue Jan 29 09:04:41 CET 2013

lapply always yields one output for every input. Try using a for loop and only copying the element once you know you want it. You will need an output index counter that is separate from the for loop index, incremented only when you copy an element.
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
Sent from my phone. Please excuse my brevity.

"Benjamin Ward (ENV)" <B.Ward at uea.ac.uk> wrote:

>Hi, This is probably a small query but one I'm struggling with: I have
>a list in which I had elements which were NA, I removed them, by doing:
>list2 <- lapply(list, na.omit),
>However this leaves the element there with  'character(0)' in place as
>well as attributes:
>[1] 1
>[1] "omit"
>I want to get rid of these elements/positions in the list, since a
>function is supposed to sample the list for elements (each element is a
>collection of about 20 numbers each).
>Ben W.
>UEA (ENV) - b.ward at uea.ac.uk
>	[[alternative HTML version deleted]]
>R-help at r-project.org mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list