I am saving my column names of a data.frame into a variable in R. Some of my columns names contain a plus sign +. R changes the + into a . when saving it into a variable. I would like to retain the + so that i can pick these columns again automatically when I need them.
Here is the command I am using to save the column names into a variable:
for (u in 1:50) {
k <- colnames[u]
f <- append(f,k)
}
## f is defined previously in my program
Here is the command I am using to get the names I need again:
file2 <- file1[,f]
Example: column1+ is named column1. in the variable f
Note: This happened to the brackets () as well as slashes /
Any Ideas how I can get around this problem?
Just so the question remains answered. Set the option
check.namestoFALSEwhile reading thedata.frameusingread.tableas:Note: As @Roland says under the comments, it is better to keep the column names clean rather than using this parameter. You may also run into situations where certain functions automatically convert the names back. For example,
You’ll have to know ALL functions that has
check.names=FALSEand remember to use them correctly. This is at least one problem I could think of. Its rather better to have the columns without conflict.Including operators such as
+in column names can also interfer with the formula model interface:You would need to use
lm(dat$b~dat[,'a+x']).