Home > Back-end >  Variable name with % symbol
Variable name with % symbol

Time:12-20

I'm working with a database where I can't change the variable names by company decision.

One of the variables is named as follows:

%Variable

I fit a model (lm object) and this variable is included.

Now I want to use the predict() function and I need to create a dataframe using this same name in one of the columns to be able to predict values. I'm doing the following:

new_x <- data.frame(X1 = 1, X2 = 0, X3 = 0, X4= 1, X5 = 0.765, `%VARIABLE` = 16.1)

predict(object = model4, newdata = new_x, level = 0.95, interval = 'confidence')

However, the new_x dataframe has the last column named as X.VARIABLE and not as %VARIABLE.

How can I fix this?

CodePudding user response:

The function names() works.

names(new_x)[6] <- "%VARIABLE"

new_x

  X1 X2 X3 X4    X5 %VARIABLE
1  1  0  0  1 0.765      16.1
  • Related