wildcard package

2017/06/12

http://will-landau.com/2017/05/21/wildcard/ 의 글을 보고 시도해 봅니다. 어디에 쓰게 될지는 모르겠지만 알아두면 언젠가 한번은 사용하게 될 것 같습니다.

install.packages("wildcard")
library(wildcard)
myths <- data.frame(myth = c("Bigfoot", "UFO", "Loch Ness Monster"),
                    claim = c("various", "day", "day"),
                    note = c("various", "pictures", "reported day"))
myths
##                myth   claim         note
## 1           Bigfoot various      various
## 2               UFO     day     pictures
## 3 Loch Ness Monster     day reported day
out = wildcard(myths, wildcard = "day", values = c("today", "yesterday"))
out
##                myth     claim               note
## 1           Bigfoot   various            various
## 2               UFO     today           pictures
## 3               UFO yesterday           pictures
## 4 Loch Ness Monster     today     reported today
## 5 Loch Ness Monster yesterday reported yesterday
wildcard(myths, wildcard = "day", values = c("today", "yesterday"), expand = FALSE)
##                myth     claim           note
## 1           Bigfoot   various        various
## 2               UFO     today       pictures
## 3 Loch Ness Monster yesterday reported today
locations <- data.frame(myth = c("Bigfoot", "UFO", "Loch Ness Monster"), origin = "where")
locations
##                myth origin
## 1           Bigfoot  where
## 2               UFO  where
## 3 Loch Ness Monster  where
rules <- list(where = c("North America", "various", "Scotland"), UFO = c("spaceship", "saucer"))
rules
## $where
## [1] "North America" "various"       "Scotland"     
## 
## $UFO
## [1] "spaceship" "saucer"
wildcard(locations, rules = rules, expand = c(FALSE, TRUE))
##                myth        origin
## 1           Bigfoot North America
## 2         spaceship       various
## 3            saucer       various
## 4 Loch Ness Monster      Scotland
numbers <- data.frame(x = 4, y = 3, z = 4444, w = 4.434)
numbers
##   x y    z     w
## 1 4 3 4444 4.434
wildcard(numbers, wildcard = 4, values = 7)
##   x y    z     w
## 1 7 3 7777 7.737