Skip to content

Instantly share code, notes, and snippets.

@mrchypark
Last active June 20, 2019 02:15
Show Gist options
  • Save mrchypark/c316823c9dbd78eea05f7e2186c8d8e2 to your computer and use it in GitHub Desktop.
Save mrchypark/c316823c9dbd78eea05f7e2186c8d8e2 to your computer and use it in GitHub Desktop.
library(readxl)
library(dplyr)
library(tidyr)
library(stringr)
tem <- read_excel("myCabinetExcelData (2).xls", col_names = F)
tem %>%
distinct(...1) %>%
pull(...1) -> col_order
tem %>%
mutate(
title = str_detect(...1, "제목"),
arti_id = cumsum(title)
) %>%
rename(
key = ...1,
value = ...2
) %>%
select(
arti_id, key, value
) %>%
group_by(arti_id, key) %>%
mutate(dup = row_number()) %>%
ungroup() %>%
mutate(arti_id = str_c(arti_id,"-",dup)) %>%
select(-dup) %>%
spread(key, value) %>%
select(
c(arti_id, col_order)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment