Replies: 8 comments 2 replies
-
students |> |
Beta Was this translation helpful? Give feedback.
-
library(tidyverse)
students <- read_csv("https://pos.it/r4ds-students-csv")
#> Rows: 6 Columns: 5
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (4): Full Name, favourite.food, mealPlan, AGE
#> dbl (1): Student ID
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
students_rename <- students |>
rename(
`Student ID` = student_id,
`Full Name` = full_name
)
#> Error in `rename()`:
#> ! Can't rename columns that don't exist.
#> ✖ Column `student_id` doesn't exist.
#> Backtrace:
#> ▆
#> 1. ├─dplyr::rename(students, `Student ID` = student_id, `Full Name` = full_name)
#> 2. ├─dplyr:::rename.data.frame(students, `Student ID` = student_id, `Full Name` = full_name)
#> 3. │ └─tidyselect::eval_rename(expr(c(...)), .data)
#> 4. │ └─tidyselect:::rename_impl(...)
#> 5. │ └─tidyselect:::eval_select_impl(...)
#> 6. │ ├─tidyselect:::with_subscript_errors(...)
#> 7. │ │ └─rlang::try_fetch(...)
#> 8. │ │ └─base::withCallingHandlers(...)
#> 9. │ └─tidyselect:::vars_select_eval(...)
#> 10. │ └─tidyselect:::walk_data_tree(expr, data_mask, context_mask)
#> 11. │ └─tidyselect:::eval_c(expr, data_mask, context_mask)
#> 12. │ └─tidyselect:::reduce_sels(node, data_mask, context_mask, init = init)
#> 13. │ └─tidyselect:::walk_data_tree(new, data_mask, context_mask)
#> 14. │ └─tidyselect:::as_indices_sel_impl(...)
#> 15. │ └─tidyselect:::as_indices_impl(...)
#> 16. │ └─tidyselect:::chr_as_locations(x, vars, call = call, arg = arg)
#> 17. │ └─vctrs::vec_as_location(...)
#> 18. └─vctrs (local) `<fn>`()
#> 19. └─vctrs:::stop_subscript_oob(...)
#> 20. └─vctrs:::stop_subscript(...)
#> 21. └─rlang::abort(...) Created on 2023-04-17 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
-
library(ggplot2)
ggplot(Indometh, aes(x=time, y=conc)) +
stat_summary(
fun=mean,
geom = "line",
linewidth = 0.3
) +
stat_summary(
fun = mean,
geom = "point",
size = 2
) +
stat_summary(
fun.data = "mean_cl_boot",
geom = "errorbar",
col = "red",
width = 0.3
) Created on 2023-04-18 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
-
library(ggplot2)
# devtools::install_github("dpastoor/PKPDdatasets")
library(PKPDdatasets)
PKPDdatasets::sd_oral_richpk |>
ggplot(aes(Time, Conc)) +
stat_summary(
fun=mean,
geom = "line",
linewidth = 0.3
) +
stat_summary(
fun = mean,
geom = "point",
size = 2
) +
stat_summary(
fun.data = "mean_cl_boot",
geom = "errorbar",
width = 0.3
) +
facet_grid(Race ~ Gender) Created on 2023-04-18 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
-
library(tidyverse)
age <- c(1, 2, 3, 5, 7, 11, 13, 18)
df <- tibble(age)
df |>
mutate(stage = if_else(age <= 1,
'infant',
if_else(age <=2,
'toddler',
if_else(age <= 12,
'childhood',
'adolescent'))))
#> # A tibble: 8 × 2
#> age stage
#> <dbl> <chr>
#> 1 1 infant
#> 2 2 toddler
#> 3 3 childhood
#> 4 5 childhood
#> 5 7 childhood
#> 6 11 childhood
#> 7 13 adolescent
#> 8 18 adolescent
df |>
mutate(stage = case_when(
age <= 1 ~ 'infant',
age <= 2 ~ 'toddler',
age <= 12 ~ 'childhood',
age <= 18 ~ 'adolescent'
))
#> # A tibble: 8 × 2
#> age stage
#> <dbl> <chr>
#> 1 1 infant
#> 2 2 toddler
#> 3 3 childhood
#> 4 5 childhood
#> 5 7 childhood
#> 6 11 childhood
#> 7 13 adolescent
#> 8 18 adolescent Created on 2023-04-25 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
-
library(tidyverse)
age <- c(1, 2, 3, 5, 7, 11, 13, 18, 43, 50)
df <- tibble(age)
df |>
mutate(stage = case_when(
age <= 1 ~ 'infant',
age <= 2 ~ 'toddler',
age <= 12 ~ 'childhood',
age <= 18 ~ 'adolescent'
))
#> # A tibble: 10 × 2
#> age stage
#> <dbl> <chr>
#> 1 1 infant
#> 2 2 toddler
#> 3 3 childhood
#> 4 5 childhood
#> 5 7 childhood
#> 6 11 childhood
#> 7 13 adolescent
#> 8 18 adolescent
#> 9 43 <NA>
#> 10 50 <NA>
df |>
mutate(stage = case_when(
age <= 1 ~ 'infant',
age <= 2 ~ 'toddler',
age <= 12 ~ 'childhood',
age <= 18 ~ 'adolescent',
TRUE ~ '꼰대'
))
#> # A tibble: 10 × 2
#> age stage
#> <dbl> <chr>
#> 1 1 infant
#> 2 2 toddler
#> 3 3 childhood
#> 4 5 childhood
#> 5 7 childhood
#> 6 11 childhood
#> 7 13 adolescent
#> 8 18 adolescent
#> 9 43 꼰대
#> 10 50 꼰대 Created on 2023-04-25 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
-
library(tidyverse)
df <- tibble(name=c("Pil", "Cha", "Jun", "Kelly", "David", "Julia", NA, NA),
food=c("Mexican", NA, "ddukboki", "bread", NA, "Japanese", "Korean", NA))
df |>
mutate(name_or_food = coalesce(name, food, "Whatever")) |>
mutate(name_na = coalesce(name, "Noname"))
#> # A tibble: 8 × 4
#> name food name_or_food name_na
#> <chr> <chr> <chr> <chr>
#> 1 Pil Mexican Pil Pil
#> 2 Cha <NA> Cha Cha
#> 3 Jun ddukboki Jun Jun
#> 4 Kelly bread Kelly Kelly
#> 5 David <NA> David David
#> 6 Julia Japanese Julia Julia
#> 7 <NA> Korean Korean Noname
#> 8 <NA> <NA> Whatever Noname Created on 2023-05-19 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
-
https://youtu.be/U0x_w3-4y-A 영상을 참고하여
아무 코드나 작성해서
reprex::reprex()
로 클립보드에 복사하여 댓글에 붙여넣기 해 주세요.기한: 2023-04-14 23:59
Created on 2023-04-14 with reprex v2.0.2
Beta Was this translation helpful? Give feedback.
All reactions