[R] [R-sig-Geo] Variables inside a for

Frede Aakmann Tøgersen FredeA.Togersen at agrsci.dk
Tue Dec 2 08:37:07 CET 2008

How about doing something like:
x <- 1:100
y1 <- 1 + 2*x + rnorm(x)
y2 <- 2 + 3*x + rnorm(x)
lm(cbind(y1,y2) ~ x)

This is much faster.

Yours sincerely / Venlig hilsen

Frede Aakmann Tøgersen
Statistician, M.Sc., Ph.D.
Modeling, Statistics and Risk Analysis

Wind and Site Competence Centre

Technology R&D
T: +45 9730 5135
M: +45 2547 6050
frtog at vestas.com

Company reg. name: Vestas Wind Systems A/S.. 
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice <http://www.vestas.com/legal/notice/owww.vestas.com/legal/notice> 
If you have received this e-mail in error please contact the sender.


From: r-sig-geo-bounces at stat.math.ethz.ch on behalf of Raphael Saldanha
Sent: Tue 02-12-2008 01:45
To: r-sig-geo at stat.math.ethz.ch; r-help at r-project.org
Cc: Ana Paula Sobral
Subject: [R-sig-Geo] Variables inside a for


I had a database with some variables in sequence. Let me say: TX01, TX02,
TX03 and TX04.

But I need to run some regressions changing the variables... so:

variable <- paste("TX0", 1:4, sep="")

for(i in 1:4){
test[i] <- lm(variable[i] ~ INCOME, data=database)

But doesn't work... lm tries to find a variable inside database named
variable[i] ...


King regards!

Raphael Saldanha

        [[alternative HTML version deleted]]

R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch

More information about the R-help mailing list