# Set libPaths.
.libPaths("/Users/im/.exploratory/R/4.4")
# Load required packages.
library(janitor)
library(lubridate)
library(hms)
library(tidyr)
library(stringr)
library(readr)
library(cpp11)
library(forcats)
library(RcppRoll)
library(dplyr)
library(tibble)
library(bit64)
library(zipangu)
library(exploratory)
library(crayon)
# Custom R function as Data.
mIp2ost4.func <- function(){
set.seed(456)
library(dplyr)
n <- 2000
npsデータ <- tibble(
回答者ID = sprintf("%04d", 1:n),
回答日 = sample(seq(as.Date("2023-01-01"), as.Date("2024-12-31"), by = "day"), n, replace = TRUE),
性別 = sample(c("男", "女"), n, replace = TRUE),
年代 = sample(c("10代", "20代", "30代", "40代", "50代", "60代"), n, replace = TRUE,
prob = c(0.05, 0.2, 0.25, 0.2, 0.2, 0.1))
) %>%
rowwise() %>%
mutate(
推奨度 = case_when(
年代 %in% c("20代", "30代") & 性別 == "女" ~ sample(9:10, 1, prob = c(0.45, 0.55)),
年代 %in% c("20代", "30代") & 性別 == "男" ~ sample(8:10, 1, prob = c(0.2, 0.4, 0.4)),
年代 == "40代" ~ sample(6:10, 1, prob = c(0.1, 0.1, 0.25, 0.3, 0.25)),
年代 == "50代" ~ sample(5:9, 1, prob = c(0.1, 0.15, 0.3, 0.3, 0.15)),
年代 == "60代" ~ sample(4:9, 1, prob = c(0.15, 0.15, 0.25, 0.25, 0.15, 0.05)),
TRUE ~ sample(7:10, 1, prob = c(0.15, 0.2, 0.35, 0.3))
)
) %>%
ungroup()
}
# Steps to produce the output
mIp2ost4.func() %>%
readr::type_convert() %>%
exploratory::clean_data_frame() %>%
arrange(回答日) %>%
mutate(回答者ID = str_c("ID-", 回答者ID)) %>%
mutate(回答者ID = str_c("ID-",str_pad(row_number(), width=4, pad=0)))