👏

データサイエンス100本ノック(構造化データ加工編)をRで解く 11 - 20

2021/11/21に公開

Top
前の問題:01-10

R-011

df_customer %>%
    dplyr::filter(
        str_ends(customer_id, "1")
    ) %>%
    head(10)

R-012

df_store %>%
    dplyr::filter(
        str_detect(address, "神奈川県横浜市")
    ) %>%
    head(10)

R-013

df_customer %>%
    dplyr::filter(
        str_detect(status_cd, regex("^[ABCDEF].*", dotall=TRUE))
    ) %>%
    head(10)

R-014

df_customer %>%
    dplyr::filter(
        str_detect(status_cd, regex(".*[1-9]$", dotall=TRUE))
    ) %>%
    head(10)

R-015

df_customer %>%
    dplyr::filter(
        str_detect(status_cd, regex("^[ABCDEF].*[1-9]$", dotall=TRUE))
    ) %>%
    head(10)

R-016

df_store %>%
    dplyr::filter(
        str_detect(tel_no, regex("[0-9]{3}-[0-9]{3}-[0-9]{4}"))
    )

R-017

df_customer %>%
    arrange(birth_day) %>%
    head(10)

R-018

df_customer %>%
    arrange(desc(birth_day)) %>%
    head(10)

R-019

df_receipt %>%
    mutate(
        amount_rank = rank(-amount)
    ) %>%
    select(
        customer_id,
        amount,
        amount_rank
        ) %>%
    # arrange(amount_rank) %>%
    head(10)

R-020

df_receipt %>%
    mutate(
        amount_rank = rank(-amount, ties.method = "first")
    ) %>%
    select(
        customer_id,
        amount,
        amount_rank
        ) %>%
    # arrange() %>%
    head(10)

次の問題:21-30

Discussion