program written in earlier version works, in the current version dose'nt

566 views
Skip to first unread message

Hanna Ouaknin

unread,
Sep 5, 2017, 4:12:15 PM9/5/17
to Davis R Users' Group
the program shows several errors:
first it shows this

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

than the error:


Error in UseMethod("group_by_") : 
  no applicable method for 'group_by_' applied to an object of class "c('matrix', 'list')" 


thank you for the help

Hanna

Rich Pauloo

unread,
Sep 5, 2017, 4:37:45 PM9/5/17
to davi...@googlegroups.com
This is because you're applying to a dplyr function (group_by) to a matrix or a list. Dplyr functions work on data.frames. You might want to try using purrr::flatten() on your list, or as.data.frame() on your matrix to coerce the object into a dataframe before using dplyr functions on it.

--
Check out our R resources at http://d-rug.github.io/
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.



--
Rich Pauloo

Rosemary Hartman

unread,
Sep 5, 2017, 4:41:55 PM9/5/17
to davi...@googlegroups.com
Hi Hanna,

For the first error, don't worry about it. It is just telling you that 'dplyr' has some functions with the same name as the pagages in base R. dplyr improved these functions, so overwrote them, but if you are not using those functions you shouldn't notice any difference. If you are using those functions, and it gives you an error, you can specify which package you want to pull them from by writing:

base::intersect 

or 

dplyr::intersect

Once in a while I also have problems with the "group_by" function. The code works the first time, but then I run it again and I get a similar error. I find that clearing the workspace usually fixes it. You can click the little "broom" icon in the Environment tab of RStudio, or:

rm(list = ls())

Then re-run all the code and see if it fixes things.

Hope that helps!
Rosemary

On Tue, Sep 5, 2017 at 1:12 PM, Hanna Ouaknin <ouak...@gmail.com> wrote:

--
Check out our R resources at http://d-rug.github.io/
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.



--

Michael Hannon

unread,
Sep 5, 2017, 6:30:14 PM9/5/17
to davi...@googlegroups.com
A couple of points:

(1) If you're concerned about the dplyr-startup messages, you can
suppress them, as:

> suppressPackageStartupMessages(library(dplyr))
>

(The package name was evidently translated from German.)

(2) Depending on the details of your data structure, the advice to
coerce it to a data frame is probably a good idea. OTOH, there *are*
pre-Hadley functions that do similar things:

> ?by
> ?tapply

so if you don't get any love from the data-frame approach, you might
look at those.

-- Mike


On Tue, Sep 5, 2017 at 1:12 PM, Hanna Ouaknin <ouak...@gmail.com> wrote:
> --
> Check out our R resources at http://d-rug.github.io/
> ---
> You received this message because you are subscribed to the Google Groups
> "Davis R Users' Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to davis-rug+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages