Ravi et. al:
My prior "solution" nagged at me, as I thought it was pretty clumsy --
I was hoping someone would show how to fix it up. As no one did, I
finally realized how to do it myself. Here's how to do the iteration
to get the right labeling with no pasting or formula() call by using
as.name(
ail.com]
Sent: Tuesday, October 27, 2015 1:50 PM
To: Ravi Varadhan
Cc: r-help@r-project.org
Subject: Re: [R] How to get variable name while doing series of regressions in
an automated manner?
Marc,Ravi:
I may misunderstand, but I think Marc's solution labels the list components but
not nece
Marc,Ravi:
I may misunderstand, but I think Marc's solution labels the list
components but not necessarily the summary() outputs. This might be
sufficient, as in:
> z <- list(y1=rnorm(10,5),y2 = rnorm(10,8),x=1:10)
>
> ##1
> results1<-lapply(z[-3],function(y)lm(log(y)~x,data=z))
> lapply(results1
> On Oct 27, 2015, at 10:19 AM, Ravi Varadhan wrote:
>
> Hi,
>
> I am running through a series of regression in a loop as follows:
>
> results <- vector("list", length(mydata$varnames))
>
> for (i in 1:length(mydata$varnames)) {
> results[[i]] <- summary(lm(log(eval(parse(text=varnames[i])))
Hi,
I am running through a series of regression in a loop as follows:
results <- vector("list", length(mydata$varnames))
for (i in 1:length(mydata$varnames)) {
results[[i]] <- summary(lm(log(eval(parse(text=varnames[i]))) ~ age + sex +
CMV.status, data=mydata))
}
Now, when I look at the result
5 matches
Mail list logo