I'm trying to write a function that regresses multiple items, then tries to predict data based on the model:

```
"tnt" <- function(train_dep, train_indep, test_dep, test_indep) 
{
    y <- train_dep
    x <- train_indep
    mod <- lm (y ~ x)
    estimate <- predict(mod, data.frame(x=test_indep))
    rmse <- sqrt(sum((test_dep-estimate)^2)/length(test_dep)) 
    print(summary(mod))
    print(paste("RMSE: ", rmse))        
}

```

If I pass the above this, it fails:

```
train_dep = vector1
train_indep <- cbind(vector2, vector3)
test_dep = vector4
test_indep <- cbind(vector5, vector6)
tnt(train_dep, train_indep, test_dep, test_indep)

```

Changing the above to something like the following works, but I want this done dynamically so I can pass it a matrix of any number of columns:

```
x1 = x[,1]
x2 = x[,2]
mod <- lm(y ~ x1+x2)
estimate <- predict(mod, data.frame(x1=test_indep[,1], x2=test_indep[,2]))

```

Looks like this could help, but I'm still confused on the rest of the process: <http://finzi.psych.upenn.edu/R/Rhelp02a/archive/70843.html>