0

I cannot figure out how to assign the column headers from my imported xlsx sheet as variables. I have several column headers, for example DAY_CHNG and INPUT_CHG. So far, I can only run gls(DAY_CHG~INPUT_CHG) by first assigning the values as variables by X<-mydata$DAY_CHG. Is there some command to get these variables assigned automatically when I import?

I had horrible problems getting the program up and running, by the way, due to firewalls at the firm for which I'm working, wondering if that's causing some of the issue.

Any help is much appreciated. Thanks!

Philipp HB
  • 169
  • 1
  • 14

2 Answers2

0

attach(mydata) will allow you to directly use the variable names. However, attach may cause problems, especially with more complex data/analyses (see Do you use attach() or call variables by name or slicing? for a discussion)

An alternative would be to use with, such as with(mydata, gls(DAY_CHG~INPUT_CHG)

Mr. Bugle
  • 325
  • 2
  • 12
0

I would suggest using the $ in order to use the headers as variables and still be able to use other data sets. All that needs to be done is assign the data to an object such as your mydata and by putting a $ immediately following, you will be able to refer to your headers as variables. As an example for your case, instead of creating a new object x, simply take what you assigned x to and put it directly into your command. gls(mydata$DAY_CHG ~ mydata$INPUT_CHG)
when it becomes more complicated with more data sets this will allow you to have access to all of them still while not limiting yourself to the data set you attach()

E. Nicholson
  • 105
  • 1
  • 5