Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1035063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:29:23+00:00 2026-05-16T14:29:23+00:00

I’d like to create a function that automatically generates uni and multivariate regression analyses,

  • 0

I’d like to create a function that automatically generates uni and multivariate regression analyses, but I’m not able to figure out how I can specify **variables in vectors…**This seems very easy, but skimming the documentation I havent figured it out so far…

Easy example

a<-rnorm(100)
b<-rnorm(100)
k<-c("a","b")
d<-c(a,b)
summary(k[1])

But k[1]=”a” and is a character vector…d is just b appended to a, not the variable names. In effect I’d like k[1] to represent the vector a.

Appreciate any answers…

//M

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:29:24+00:00Added an answer on May 16, 2026 at 2:29 pm

    You can use the “get” function to get an object based on a character string of its name, but in the long run it is better to store the variables in a list and just access them that way, things become much simpler, you can grab subsets, you can use lapply or sapply to run the same code on every element. When saving or deleting you can just work on the entire list rather than trying to remember every element. e.g.:

    mylist <- list(a=rnorm(100), b=rnorm(100) )
    names(mylist)
    summary(mylist[[1]])
    # or
    summary(mylist[['a']])
    # or
    summary(mylist$a)
    # or 
    d <- 'a'
    summary(mylist[[d]])
    
    # or
    lapply( mylist, summary )
    

    If you are programatically creating models for analysis with lm (or other modeling functions), then one approach is to just subset your data and use the “.”, e.g.:

    yvar <- 'Sepal.Width'
    xvars <- c('Petal.Width','Sepal.Length')
    fit <- lm( Sepal.Width ~ ., data=iris[, c(yvar,xvars)] )
    

    Or you can build the formula using “paste” or “sprintf” then use “as.formula” to convert it to a formula, e.g.:

    yvar <- 'Sepal.Width'
    xvars <- c('Petal.Width','Sepal.Length')
    my.formula <- paste( yvar, '~', paste( xvars, collapse=' + ' ) )
    my.formula <- as.formula(my.formula)
    fit <- lm( my.formula, data=iris )
    

    Note also the problem of multiple comparisons if you are looking at many different models fit automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.