buildPattern {conjurer} | R Documentation |
Builds data based on a pattern. This function uses another internal function genPattern
.
buildPattern(n, parts, probs)
n |
A natural number. This specifies the number of data points to build. |
parts |
A natural number. This specifies the parts that make up the pattern. |
probs |
A number between 0 and 1. |
This function helps in generating data based on a pattern. To explain in simple terms, this function aims to perform the exact opposite of a regular expression i.e regex function. In other words, this function generates data given a generic pattern. The steps in the process of building data from a pattern is as follows.
Identify the parts that make up the data. Ideally, these parts have a pattern and a probabilistic distribution of their own. For example, a phone number has three parts namely, country code, area code and a number.
Assign probabilities to each of the above parts. If a part contains only one member, then the corresponding probability must be 1. However, if there are multiple members in the part, then each member must have a probability provided in the respective order.
A vector.
parts <- list(c("+91","+44","+64"), c(491,324,211), c(7821:8324))
probs <- list(c(0.25,0.25,0.50), c(0.30,0.60,0.10), c())
phoneNumbers <- buildPattern(n=20,parts = parts, probs = probs)
head(phoneNumbers)
parts <- list(c("+91","+44","+64"), c("("), c(491,324,211), c(")"), c(7821:8324))
probs <- list(c(0.25,0.25,0.50), c(1), c(0.30,0.60,0.10), c(1), c())
phoneNumbers <- buildPattern(n=20,parts = parts, probs = probs)
head(phoneNumbers)