Omg, that was really a bit hasty. I'm sorry. But it is still coming to an error message...

Just needed some simplification

library(circular)
#> 
#> Attaching package: 'circular'
#> The following objects are masked from 'package:stats':
#> 
#>     sd, var
library(dplyr)
#> 
#> 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
dat <- tibble::tribble(
  ~dir, ~degree,
  "A",      2L,
  "A",     12L,
  "B",     78L,
  "B",    257L,
  "C",     57L,
  "C",    198L
)

dat %>%
  group_by(dir) %>%
  summarise(
    circ_mean =
      circular(degree, units = "degrees", rotation = "counter", zero=0, modulo="2pi") %>%
      #data to circular format
  mean.circular())
#> # A tibble: 3 × 2
#>   dir   circ_mean 
#>   <chr> <circular>
#> 1 A       7.0     
#> 2 B     167.5     
#> 3 C     127.5

# ungrouping not needed
dat
#> # A tibble: 6 × 2
#>   dir   degree
#>   <chr>  <int>
#> 1 A          2
#> 2 A         12
#> 3 B         78
#> 4 B        257
#> 5 C         57
#> 6 C        198
ungroup(dat)
#> # A tibble: 6 × 2
#>   dir   degree
#>   <chr>  <int>
#> 1 A          2
#> 2 A         12
#> 3 B         78
#> 4 B        257
#> 5 C         57
#> 6 C        198
dat
#> # A tibble: 6 × 2
#>   dir   degree
#>   <chr>  <int>
#> 1 A          2
#> 2 A         12
#> 3 B         78
#> 4 B        257
#> 5 C         57
#> 6 C        198

@technocrat Thank you very much, you help me enormously. Two questions:

The reprex works as planned, but with the real data, I get a new error...

``` r
data %>%
  group_by(dir) %>%
  summarise(
    circ_mean =
      circular(degree, units = "degrees", rotation = "counter", zero=0, modulo="2pi")%>%#data to circular format
      mean.circular())
#> Error in data %>% group_by(dir) %>% summarise(circ_mean = circular(degree, : konnte Funktion "%>%" nicht finden

My second question: what was my mistake, I can use your improvements, but I want to understand...
Thanks!

Did you include loading this?

Yes, dyplr is included.

Means that the magrittr package is not in namespace, which it should be if dplyr is loaded. Try adding

library (magrittr)

If not found, reinstall dyplr

Or replace %>% with |>, should work as well :slight_smile:

1 Like

Thanks for the hint, but it still doesn't work.

You should say more about the problems you have if you want help to solve them.
For better assistance , you are recommended to justify to the forum users trying to help you that 'it still doesn't work' by quoting back the code you are trying to use, and also the error or incorrect result that you get..

@nirgrahamuk I'm sorry, I completely forgot. Enclosed the reprex.

``` r
library(dplyr)
#> Warning: Paket 'dplyr' wurde unter R Version 4.0.5 erstellt
#> 
#> Attache Paket: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(magrittr)
#> Warning: Paket 'magrittr' wurde unter R Version 4.0.5 erstellt
data %>%
  group_by(dir) %>%
  summarise(
    circ_mean =
      circular(degree, units = "degrees", rotation = "counter", zero=0, modulo="2pi")%>%#data to circular format
      mean.circular())
#> Error in UseMethod("group_by"): nicht anwendbare Methode für 'group_by' auf Objekt der Klasse "function" angewendet

Created on 2022-01-31 by the reprex package (v2.0.1)

if your starting data.frame that is loaded into your environment is called dat but you typed out data in your most recent variation, that would explain the error...
Can you clarify your use of data ?

Oh, excuse me. First, I created an example, where I used "dat" as dataset. In the real dataset, it's called data.

lets review...
does the following give you an error ?

dat <- tibble::tribble(
  ~dir, ~degree,
  "A",      2L,
  "A",     12L,
  "B",     78L,
  "B",    257L,
  "C",     57L,
  "C",    198L
)
library(circular)
dat %>%
  group_by(dir) %>%
  summarise(
    circ_mean =
      circular(degree, units = "degrees", rotation = "counter", zero=0, modulo="2pi")%>%#data to circular format
      mean.circular())

No, everything works as planned.

Do you require additional support ?
Your earlier error Error in UseMethod("group_by"): nicht anwendbare Methode für 'group_by' auf Objekt der Klasse "function" angewendet
tells me that at the time your code was run, the data object name was not bound to your loaded data, but rather to the default utils::data() function.

1 Like

which is why I never use df, data, c, D, t, among others, as the name of objects that I create. :wink:

I see, I have to learn really much... Sorry @all for my confused approach.
Now, I have created a reprex from the original data and it's strange. I created a dataset with 6 cases (mydata) and all is fine. But if I waive the case selection, I get the same error as always. The next problem is, that when I create the reprex, I get more error messages...

``` r
data.frame(
      degree = c(313.922112119583,340.090834916981,
                 275.479983711446,205.458659115787,3.96963691809708,325.187911117228),
         dir = as.factor(c("GWTL", "GWTL", "ING", "ING", "BP", "BP"))
)
#>       degree  dir
#> 1 313.922112 GWTL
#> 2 340.090835 GWTL
#> 3 275.479984  ING
#> 4 205.458659  ING
#> 5   3.969637   BP
#> 6 325.187911   BP

Created on 2022-02-01 by the reprex package (v2.0.1)

library(dplyr)
#> Warning: Paket 'dplyr' wurde unter R Version 4.0.5 erstellt
#> 
#> Attache Paket: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(magrittr)
#> Warning: Paket 'magrittr' wurde unter R Version 4.0.5 erstellt
library(circular)
#> Warning: Paket 'circular' wurde unter R Version 4.0.5 erstellt
#> 
#> Attache Paket: 'circular'
#> The following objects are masked from 'package:stats':
#> 
#>     sd, var
mydata %>%
  dplyr::group_by(dir) %>%
  summarise(
    circ_mean =
      circular::circular(degree, units = "degrees", rotation = "counter", zero=0, modulo="2pi")%>%#data to circular format
      circular::mean.circular())
#> Error in dplyr::group_by(., dir): Objekt 'mydata' nicht gefunden

Created on 2022-02-01 by the reprex package (v2.0.1)

I'm afraid I don't know what this means but I can explain your reprex issue.

The purpose of a reprex is to reproduce your issue on someone else's machine. Example data is needed , therefore the reprex script will need to be responsible for guaranteeing the loading or artificial construction of some data for the code shared to operate on. I.e. in your reprex you have omitted a stand in for mydata.
Or in other words, your failing reprex assumes the presence of mydata , but this is a false assumption.

Thank you very much for your kind support! I have found the problem. There was one case with some NaNs. Without this case, respectively an imputation, it works :slight_smile:
Thank you for your patience!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.