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

Martin Maechler maechler at stat.math.ethz.ch
Mon May 2 10:49:20 CEST 2016


>>>>> 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.



More information about the R-help mailing list