[R] Removing NAs from dataframe (for use in Vioplot)

Bert Gunter bgunter.4567 at gmail.com
Mon May 2 15:20:52 CEST 2016


Martin et. al.:

na.omit(frame) will remove all rows/cases in which an NA occurs.  I'm
not sure that this is what the OP wanted, which seemed to be to
separately remove NA's from each column and plot the resulting column.
This is what the lapply (and the OP's provided code) does, anyway.

Also, lapply() produces a single list (of vectors), not a "series of lists" .

Corrections happily accepted if I'm in error.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, May 2, 2016 at 1:49 AM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
>>>>>> Mike Smith <mike at hsm.org.uk>
>>>>>>     on Sun, 1 May 2016 08:15:44 +0100 writes:
>
>     >>>> On Apr 30, 2016, at 12:58 PM, Mike Smith
>     >>>> <mike at hsm.org.uk> wrote: Hi
>
>     >>>> First post and a relative R newbie....
>
>     >>>> I am using the vioplot library to produce some violin
>     >>>> plots.
>
>     DW> It's a package, .... not a library.
>
> [yes!]
>
>
>     >>>> 1. Is there a more elegant way of automatically
>     >>>> stripping the NAs, passing the columns to the function
>     >>>> along with the header names??
>
>     >>> ds2 <- lapply( ds1, na.omit)
>
>
>     > Fantastic - that does the trick! Easy when you know how!!
>
>     > Follow-on: is there a way feed all the lists from ds2 to
>     > vioplot? It is now a series of lists (rather than a
>     > dataframe - is that right?).
>
> Yes, that's right.  So after all the above was not really
> perfect :
>
>   na.omit() has been designed as a generic function and has always
>   had a method for "data.frame"; so, really
>
>     ds.noNA <- na.omit(ds1)
> or  ds0NA   <- na.omit(ds1)
>
> (choosing "expressive names")
>
> is what you want.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list