I have a data.frame where I want to 'clean' the names of the columns:
>names(Data)
[1] "tBodyAcc.mean...X"
[2] "angle.X.gravityMean."
[3] "fBodyBodyGyroJerkMag.mean.."
[4] "fBodyAccMag.meanFreq.."
.
.
I am using the following code:
names(Data)<-gsub('[mM]ean',' Mean ',names(Data))
names(Data)<-gsub('[Ff]req',' Frequency ',names(Data))
names(Data)<-gsub('^t','Time ',names(Data))
names(Data)<-gsub('\\.',' ',names(Data))
to get the following:
[1] "Time BodyAcc Mean X"
[2] "angle X gravity Mean "
[3] "fBodyBodyGyroJerkMag Mean "
[4] "fBodyAccMag Mean Frequency "
Is there a way to impliment that in one line or another more elegant way than this one?
You could also try
stri_replace_all_regex
from thestringi
package: