editCharCols {NMdata} | R Documentation |
Replace strings in character character columns of a data set
Description
Replace strings in character character columns of a data set
Usage
editCharCols(data, pattern, replacement, as.fun, ...)
Arguments
data |
The data set to edit. |
pattern |
Pattern to search for in character columns. Passed to 'gsub()'. By default, 'gsub()' works with regular expressions. See ... for how to disable this if you want to replace a specific string. |
replacement |
pattern or string to replace with. Passed to 'gsub()'. |
as.fun |
The default is to return data as a data.frame. Pass a function (say tibble::as_tibble) in as.fun to convert to something else. If data.tables are wanted, use as.fun="data.table". The default can be configured using NMdataConf. |
... |
Additional arguments passed to 'gsub()'. Especially, notice fixed=TRUE will disable interpretation of 'pattern' and 'replace' as regular expressions. |
Examples
### remove commas from character columns
dat <- data.frame(A=1:3,text=cc(a,"a,d","g"))
editCharCols(dat,pattern=",","")
### factors are not edited but result in an error
## Not run:
dat <- data.frame(A=1:3,text=cc(a,"a,d",g),fac=cl("a","a,d","g"))
editCharCols(dat,pattern=",","")
## End(Not run)
[Package NMdata version 0.1.6 Index]