Hi, I have a variable in R, its name is just a single underscore "_", is it against R…
- User
Hi, I have a variable in R, its name is just a single underscore "_", is it against R standards ?
- Assistant
In R, using a single underscore
_as a variable name is technically allowed but not recommended.Why?
- Allowed by syntax: R permits a wide variety of valid variable names, including a single underscore, because
_is not a reserved keyword in R. - Potential for confusion: Traditionally,
_is used in many programming languages (like Python) as a "throwaway" variable or placeholder; in R it doesn't have this special meaning. - May cause readability issues: Using
_can confuse readers of your code since it is non-descriptive. - Possible conflicts with tidyverse: The use of underscore
_as a variable name might cause confusion with the tidyverse style where is commonly seen as part of function names or as just a special symbol (and in some contexts, you might use , plus underscore for variable names).
- Allowed by syntax: R permits a wide variety of valid variable names, including a single underscore, because
- User
i have an error in this code dataset[!train_mask, ] %>% confusionMatrix(data = predict(model, newdata = ., type = 'raw'), reference = .$CULTURE) Erreur dans confusionMatrix.default(., data = predict(model, newdata = ., : positive argument must be character
- Assistant
- User
how to compute kappa from sensitivity and specificity
- Assistant
- User
use logical instead of factors
codedataset[!train_mask, ] %>% mutate(truth = (CULTURE == 'BTN') |> factor(levels = c(F, T)) , predicted = (predict(model, newdata = ., type = 'raw') == 'BTN') |> factor(levels = c(F, T))) |> with(confusionMatrix(data = predicted, reference = truth, positive = 'TRUE')) -> metrics* - Assistant
You want to use logical vectors (
TRUE/FALSE) internally rather than factors but keep compatibility withconfusionMatrix().confusionMatrix()expects factors fordataand , but you can create factors with levels derived from logical vectors easily. - User
generate ggplot with bars representing kappa by ntree value, grouping and colouring by year
- Assistant
Certainly! Here's an example of how to generate a ggplot2 bar plot showing Kappa values by
ntree, with bars grouped and coloured byyear.
Assumptions:
- You have a data frame called
dfwith columns:ntree(numeric or factor)year(factor or character)kappa(numeric)
Example data frame:
- You have a data frame called