── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# data(package="Ecdat") importe le package Ecdat.Yogurt %>%as.tibble() -> df
Warning: `as.tibble()` was deprecated in tibble 2.0.0.
ℹ Please use `as_tibble()` instead.
ℹ The signature and semantics have changed, see `?as_tibble`.
# ancienne méthode.Yogurt%>%select(choice)%>%table()%>%# calcul de la fréquence de choice (variable texte)prop.table()%>%round(5) # porp.table fait la conversion en proportion
Yogurt %>%summarise(across(where(is.numeric) &!all_of("id"), list(Mean = mean, Sd = sd), na.rm =TRUE)) # summarise est une statistique descriptive, across where is numeric = parmi les variables numerique, &= condition et, all_of= tout sauf, list de moyenne et d'écart type, na.rm= cherche valeur manquante.
Warning: There was 1 warning in `summarise()`.
ℹ In argument: `across(...)`.
Caused by warning:
! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
Supply arguments directly to `.fns` through an anonymous function instead.
# Previously
across(a:b, mean, na.rm = TRUE)
# Now
across(a:b, \(x) mean(x, na.rm = TRUE))
# A tibble: 100 × 3
groupe x y
<chr> <dbl> <dbl>
1 C 46.7 23.7
2 C 39.8 46.2
3 C 39.3 27.9
4 B 53.0 31.5
5 C 54.5 33.2
6 B 50.5 27.6
7 B 59.2 32.6
8 B 70.5 31.8
9 C 45.1 28.9
10 A 26.9 30.3
# ℹ 90 more rows
data %>%summarise(count =n(), # Nombre d'observations par groupemean_x =mean(x, na.rm =TRUE),sd_x =sd(x, na.rm =TRUE),min_x =min(x, na.rm =TRUE),max_x =max(x, na.rm =TRUE),mean_y =mean(y, na.rm =TRUE),sd_y =sd(y, na.rm =TRUE) )
# A tibble: 9 × 3
id matiere note
<dbl> <chr> <dbl>
1 1 math 80
2 1 science 75
3 1 english 78
4 2 math 90
5 2 science 95
6 2 english 85
7 3 math 85
8 3 science 88
9 3 english 82
Pivoter le dataframe.
Le data frame est dans un format peu commode qui s’appelle un format wide. Il y a beaucoup de colonne (1+1+4+4=10 colonnes). Il est plus commmode et plus parlant statistiquement de créer un format long avec des colonnes id, choice, feat, price mais on sera onbligé d’ajouter une autre colonne qui identifie la marque en question.
Yogurt |># création d'une colonne achat comprenant les numéros de ligne.mutate(purshase =as.integer(row_number()),id=as.integer(id)) |># nouvelle forme de pipepivot_longer(cols =starts_with("price") |starts_with("feat"), # fonction qui pivote les colonnes commençant par "price" et "feat".names_to =c(".value", "brand"),names_sep ="\\.") |>relocate( choice, .after =last_col())->Yogurt_longYogurt_long