genPattern: Generate a pattern

View source: R/genPattern.R

genPatternR Documentation

Generate a pattern


Generates data based on a pattern. This function is used by another internal function buildPattern.





A list of lists. The element values of the sublist is a vector of characters(string or numeric or special character) and the element probs is a vector of probabilities. The range of the probs is 0 to 1 and length of the probs vector is either equal to length of values or NULL.


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 input is a list of components that make up the pattern. Each component i.e element of the list is a also list with two vectors namely values and probs. The vector values has the set of values out of which one of them is selected randomly. If this random selection is supposed to be completely random, then the next vector probs can be left empty i.e. NULL. However, if the random selection of values is expected to follow a a pre-determined probabilistic distribution, then the probabilities must be provided explicitly. To explain further, if there are three values a, b, c and their probabilistic distribution must be 25 percent, 50 percent and 25 percent respectively, then the vector values will take the form c(a,b,c) and the vector probs will take the form c(0.25,0.5,0.25).


A character vector.

See Also


conjurer documentation built on Jan. 22, 2023, 1:16 a.m.