Description Usage Arguments Value See Also Examples
a function to change column names
1 |
x |
A dataframe, list or matrix with column names |
pattern |
A string |
replacement |
A string |
dim |
A character either "c" for selection of columns or "r" for selection of rows, if x is a list this parameter has no meaning |
gl |
A boolean, if TRUE (the default) all occurences in the input strings (row or column names) are replaced, if FALSE only the first occurence in every string is replaced. |
A dataframe, list or matrix where the columns or rows are renamed based on the 'Regex' substitution defined in the pattern and the replacement. By default column are renamed, unless the dim parameter specifies "r" for rows. The default is to use gsub (replacing all occurences of pattern in each column name), to replace only the first occurence set gl to FALSE.
For lists the function acts on the highest level of the list and this is irrespective of the gl parameter.
regex{base}
1 2 3 4 5 6 7 8 9 | head(csub(iris, "\\.", "-")) # will change all dots in column names in "-"
head(csub(iris, "[pP]etal", "Beetle"))
# a more complex example showing the power of 'regex'
head(csub(data.frame(WorldPhones),"^([NM](?:\\w{2})?\\.)Amer", "\\1America"))
# this example will also work on other types (the call data.frame is not necessary)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.