R - Error in Usemethod("Groups"):No Applicable Method for 'Groups' Applied to an Object of Class "Character"

Error in UseMethod(select) : no applicable method for 'select' applied to an object of class character

Two problems:

  • The first argument for your return_coef function is a data.frame named df1, yet you are calling it with df1$date2 (a string). I think you should instead start with

    mapply(return_coef, list(df1), df1$date2, df1$Category)

    (though this does error currently, see the next bullet).

    The list(df1) in this case means that the whole df1 will be passed as the first argument for each of the pairs from df1$date2 and df1$Category.

  • It now fails with argument "var1" is missing, with no default, but I suspect you were working towards that. I'll choose a couple of random names and ... something happens.

Ultimately, the function is fine as-is, just change your mapply use as:

mapply(return_coef, list(df1), df1$date2, df1$Category, var1 = "a1", var2 = "a2")
# [1] 6.539702 4.000000 1.000000 3.000000

Because both var1 and var2 are length-1, they are recycled for all calls to return_coef (as their named arguments).

Since you're using dplyr, this can be neatly put into a pipe a little more directly than using cbind(...):

library(dplyr)
df1 %>%
transmute(
date2, Category,
coef = mapply(return_coef, list(cur_data()), date2, Category, var1 = "a1", var2 = "a2")
)
# date2 Category coef
# 1 2021-06-27 ABC 6.539702
# 2 2021-07-01 ABC 4.000000
# 3 2021-07-02 ABC 1.000000
# 4 2021-07-03 ABC 3.000000

I use transmute instead of a preceding select(date2, Category) because the function needs variables present in the whole frame. I could easily have done mutate(coef=..) %>% select(date2, Category, coef) as well.

Error in UseMethod(SK) : no applicable method for 'SK' applied to an object of class character

I looked into the ScottKnott package and the SK help. The model argument is not described. Your code should run with

library(ScottKnott)

sk1 <- with(Data,
SK(kappa ~ classifier,
which='classifier')
)

returning

#> Results
#> Means G1 G2
#> U-KNNIG4 0.49 a
#> U-KNNCFS 0.49 a
#> U-KNNCON 0.16 b
#>
#> Sig.level
#> 0.05
#>
#> Statistics
#> lambda chisq dfchisq pvalue evmean dferror
#> Clus 1 13 7.2 2.6 0.0038 0.0063 27
#> Clus 2 0 5.5 1.8 1.0000 0.0063 27
#>
#>
#> Clusters
#> ################# Cluster 1 ################
#> {G1}: U-KNNIG4 U-KNNCFS
#> {G2}: U-KNNCON
#> ################# Cluster 2 ################
#> {G1}: 0
#> {G2}: NA

error no applicable method for 'select_' applied to an object of class character

library(dplyr)

#Read the csv
Old_Data <- read.csv("K:/International/New Miestone.csv", stringsAsFactors = FALSE)

#Rename all the columns and select required columns
New_Data <- Old_Data %>%
rename_all(funs(c("Enrol.Year", "VTAC.Course.Code",...))) %>%
select(Enrol.Year, VTAC.Course.Code, ...)

#Write the csv
write.csv(New_Data,path)

Error in UseMethod(select) : no applicable method for 'select' applied to an object of class c('integer', 'numeric')

Although it is difficult to troubleshoot without having some of your data, I would first make the library explicit in the function calls, as it may be trying to use select from another library.

library(dplyr)
library(tidyr)

y <- mydata_final_distinct %>%
dplyr::select(Case_ID, starts_with (Effect_)) %>%
tidyr::pivot_longer(-Case_ID, names_to = 'symptoms', values_to = adr) %>%
dplyr::distinct(Case_ID, 'symptoms', adr, .keep_all = TRUE) %>%
dplyr::count(adr) %>%
dplyr::arrange(desc(n))


Related Topics



Leave a reply



Submit