Skip to content

lm: eval(parse(text=)) works on one side y/x but not on both?

8 messages · Matthieu Stigler, Gabor Grothendieck

#
Hi

My goal is to do a (multiple) regression, just knowing that my Y 
variables will be the say k first variables of a matrix/data frame. I 
thought I should do it with eval(parse)) but encounter a strange problem.

See:
lm(y~.-y, data=freeny) #that's what I want to do in the one equation case
#Problem is I don't know name of the variable... only that it is the 
first one...
#so idea is to just take first name
a<-colnames(freeny)
#and then use eval(parse(text=a[1]))

#it works if I replace y on either the left or right side:
lm(eval(parse(text=a[1]))~.-y, data=freeny) #does the same
lm(y~.-eval(parse(text=a[1])), data=freeny)

#but not if I do this call twice:
lm(eval(parse(text=a[1]))~.-eval(parse(text=a[1])), data=freeny)
#variable I wanted to remove (y) ist still there

Do you understand why I can call eval(parse) only once? Should I try a 
update workaround? Or have idea of any other solution? Maybe there is 
something much simpler I'm missing:-(

Thanks a lot!!!

Matthieu Stigler
#
Thanks for answering so fast!!
:-)
Ok that's working for the one equation case :-) Was example case...

But now I want to have not only first column of freeny on the left but 
both first? And I don't know their names a priori...

Thanks!
#
Gabor Grothendieck a ?crit :
clean and clever!!! Thanks a lot!! You really simplified the code!!!

Just for curiosity, do you see why parse(eval)) was not working twice in 
same formula?

thanks a lot!!

Matthieu
#
Yes, was wondering that other code line did not change so much :-)

Thanks a lot!

2009/11/30 Gabor Grothendieck <ggrothendieck at gmail.com>: