A space is present in front of some of my variables, across rows and columns. I would like to replace all variables that contain a space, by the same variable without the space. I could do it for each of the variables but it is quite fastidious and I am sure there is a more elegant way of doing it.
df$var[df$var == " X"] <- "X"
I did this for each of my variables and for each of the levels of the variables. Could I write a function that automatically removes the space?