You can remove a column in a dataframe containing special characters using regular expressions with the gsub()
function. Here's an example:
main.r255 chars9 lines
In the above code, grepl("[^[:alnum:]]", colnames(df), perl = TRUE)
identifies the column names which have non-alphanumeric characters using a regular expression. The gsub()
function creates a new dataframe without these columns. This results in a dataframe with only columns having alphanumeric characters in their names.
gistlibby LogSnag