I have the following columns in my data.frame:
services_01 services_02 services_03 services_04
Privacy Policy NA NA NA
Global Expense Management Privacy Policy NA NA
Exception & Cost Admin Global Cost Estimate Global Expense Management Privacy Policy
I created them by using df <- cSplit(df, 'services', ',').
Note that services was a comma-separated list, and after running the cSplit function, I get several new columns.
The problem is, it converts them to factors. I would like them to be characters.
I see the method takes a parameter type.convert but I don't know how to use it.
The documentation says this:
type.convert Logical. Should type.convert be used to convert the result of each column? This would add a little to the execution time.
How can I convert all the factors above to simple characters?
You can convert the 'factor' columns to 'character' using the data.table methods as the output of cSplit is a data.table
df1 <- df[, lapply(.SD, as.character)]
Set type.convert = F to keep columns as strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With