根据以下数据,如何添加第三个Type
列?医院类型将根据医院名称中的某些单词确定。
Word Type
Government Government
Govt Government
St Jude Religious
Catholic Religious
District District
Community Community
Divine Mercy Religious
St. Luke Religious
St. Theresa Religious
Islamic Religious
Babtist Religious
数据:
df = structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
Hospital = c("A Government Hospital", "Government B Hospital",
"C Govt Hospital", "D St Jude Hospital", "D Catholic Hospital",
"Catholic E Hospital", "F District Hospital", "G Community Hospital",
"H Divine Mercy Hospital", "I St. Luke Hospital", "J St. Theresa Hospital",
"Babtist Hospital")), class = "data.frame", row.names = c(NA,
-12L))
# Desired df
df_desired = Hospital = c("A Governtment Hospital", "Goverment B Hospital",
"C Govt Hospital", "D St Jude Hospital", "D Catholic Hospital",
"Catholic E Hospital", "F District Hospital", "G Community Hospital",
"H Divine Mercy Hospital", "I St. Luke Hospital", "J St. Theresa Hospital",
"Babtist Hospital"), Type = c("Government", "Government",
"Religious", "Religious", "Religious", "Religious", "District",
"Community", "Religious", "Religious", "Religious", "Religious"
)), class = "data.frame", row.names = c(NA, -12L))
1条答案
按热度按时间hwamh0ep1#
如果我们有键/值数据集,可以使用
fuzzyjoin
中的regex_left_join
数据