title: Error in UseMethod("select") : no applicable method for 'select' applied to an object of class "character"
body: <p>This question is very similar to this one <a href="https://stackoverflow.com/questions/69520290/make-coefficient-for-all-dates-categories">Make coefficient for all dates/categories</a>, what is different is a few things in the <code>return_coef</code> function. You will see that I can generate the coefficients for each day/category, but when I ask to do it for everyone at once, I get the following error:</p>
  <pre><code>Error in UseMethod(&quot;select&quot;) : 
    no applicable method for 'select' applied to an object of class &quot;character&quot; 
  </code></pre>
  <p>Executable code below:</p>
  <pre><code>library(dplyr)
  library(tidyverse)
  library(lubridate)
  
  
    df1 &lt;- structure(
      list(date1= c(&quot;2021-06-26&quot;,&quot;2021-06-26&quot;,&quot;2021-06-26&quot;,&quot;2021-06-26&quot;),
           date2 = c(&quot;2021-06-27&quot;,&quot;2021-07-01&quot;,&quot;2021-07-02&quot;,&quot;2021-07-03&quot;),
           Category = c(&quot;ABC&quot;,&quot;ABC&quot;,&quot;ABC&quot;,&quot;ABC&quot;),
           Week= c(&quot;Saturday&quot;,&quot;Wednesday&quot;,&quot;Thurday&quot;,&quot;Saturday&quot;),
           DR1 = c(5,4,1,1),
           DRM01 = c(8,4,1,0), DRM02= c(7,4,2,0),DRM03= c(6,9,5,0),
           DRM04 = c(5,5,4,0),DRM05 = c(5,5,4,0),DRM06 = c(7,5,4,0),DRM07 = c(2,5,4,0),DRM08 = c(2,5,4,0)),
      class = &quot;data.frame&quot;, row.names = c(NA, -4L))
  
  
    return_coef &lt;- function(df1, dmda, CategoryChosse, var1, var2, gnum=0, graf=1) {
    
    x&lt;-df1 %&gt;% select(starts_with(&quot;DRM0&quot;))
    
    x&lt;-cbind(df1, setNames(df1$DR1 - x, paste0(names(x), &quot;_PV&quot;)))
    PV&lt;-select(x, date2,Week, Category, DR1, ends_with(&quot;PV&quot;))
    
    med&lt;-PV %&gt;%
      group_by(Category,Week) %&gt;%
      dplyr::summarize(dplyr::across(ends_with(&quot;PV&quot;), median))
    
    SPV&lt;-df1%&gt;%
      inner_join(med, by = c('Category', 'Week')) %&gt;%
      mutate(across(matches(&quot;^DRM0\\d+$&quot;), ~.x + 
                      get(paste0(cur_column(), '_PV')),
                    .names = '{col}_{col}_PV')) %&gt;%
      select(date1:Category, DRM01_DRM01_PV:last_col())
    
    SPV&lt;-data.frame(SPV)
    
    mat1 &lt;- df1 %&gt;%
      dplyr::filter(date2 == dmda, Category == CategoryChosse) %&gt;%
      select(starts_with(&quot;DRM0&quot;)) %&gt;%
      pivot_longer(cols = everything()) %&gt;%
      arrange(desc(row_number())) %&gt;%
      mutate(cs = cumsum(value)) %&gt;%
      dplyr::filter(cs == 0) %&gt;%
      pull(name)
    
    (dropnames &lt;- paste0(mat1,&quot;_&quot;,mat1, &quot;_PV&quot;))
    
    SPV &lt;- SPV %&gt;%
      filter(date2 == dmda, Category == CategoryChosse) %&gt;%
      select(-any_of(dropnames))
    
    if(length(grep(&quot;DRM0&quot;, names(SPV))) == 0) {
      SPV[head(mat1,10)] &lt;- NA_real_
    }
    
    datas &lt;-SPV %&gt;%
      dplyr::filter(date2 == ymd(dmda)) %&gt;%
      group_by(Category) %&gt;%
      dplyr::summarize(dplyr::across(starts_with(&quot;DRM0&quot;), sum)) %&gt;%
      pivot_longer(cols= -Category, names_pattern = &quot;DRM0(.+)&quot;, values_to = &quot;val&quot;) %&gt;%
      mutate(name = readr::parse_number(name))
    colnames(datas)[-1]&lt;-c(var1,var2)
    datas$days &lt;- datas[[as.name(var1)]]
    datas$numbers &lt;- datas[[as.name(var2)]]
    
    datas &lt;- datas %&gt;% 
      group_by(Category) %&gt;% 
      slice((as.Date(dmda) - min(as.Date(df1$date1) [
        df1$Category == first(Category)])):max(days)+1) %&gt;%
      ungroup
    
    m&lt;-df1 %&gt;%
      group_by(Category,Week) %&gt;%
      dplyr::summarize(dplyr::across(starts_with(&quot;DR1&quot;), mean))
    
    m&lt;-subset(m, Week == df1$Week[match(ymd(dmda), ymd(df1$date2))] &amp; Category == CategoryChosse)$DR1
    
    if (nrow(datas)&lt;=2){
      val&lt;-as.numeric(m)
    }
    
    else{
      mod &lt;- nls(numbers ~ b1*days^2+b2,start = list(b1 = 0,b2 = 0),data = datas, algorithm = &quot;port&quot;)
      coef&lt;-coef(mod)[2]
      val&lt;-as.numeric(coef(mod)[2])
    }
    
    
    return(val)
    
  }
  
  All&lt;-cbind(df1 %&gt;% select(date2, Category), coef = mapply(return_coef, df1$date2, df1$Category))
  
  Error in UseMethod(&quot;select&quot;) : 
    no applicable method for 'select' applied to an object of class &quot;character&quot;
  </code></pre>
  <p>If I want to know the coefficient for each one separately, I can do it.</p>
  <pre><code>return_coef(df1, &quot;2021-06-27&quot;,&quot;ABC&quot;, var1=0,var2=1)
  [1] 6.539702
  return_coef(df1, &quot;2021-07-01&quot;,&quot;ABC&quot;, var1=0,var2=1)
  [1] 4
  return_coef(df1, &quot;2021-07-02&quot;,&quot;ABC&quot;, var1=0,var2=1)
  [1] 1
  return_coef(df1, &quot;2021-07-03&quot;,&quot;ABC&quot;, var1=0,var2=1)
  [1] 3
  </code></pre>