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

  • SEARCH
  • Home
  • 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 5945207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:38:56+00:00 2026-05-22T16:38:56+00:00

This is something which data analysts do all the time (especially when working with

  • 0

This is something which data analysts do all the time (especially when working with survey data which features missing responses.) It’s common to first multiply impute a set of compete data matrices, fit models to each of these matrices, and then combine the results. At the moment I’m doing things by hand and looking for a more elegant solution.

Imagine there’s 5 *.csv files in the working directory, named dat1.csv, dat2.csv, … dat5.csv. I want to estimate the same linear model using each data set.

Given this answer, a first step is to gather a list of the files, which I do with the following

csvdat <- list.files(pattern="dat.*csv")

Now I want to do something like

for(x in csvdat) {
    lm.which(csvdat == "x") <- lm(y ~ x1 + x2, data = x)
}

The “which” statement is my silly way of trying to number each model in turn, using the location in the csvdat list the loop is currently up to. that is, I’d like this loop to return a set of 5 lm objects with the names lm.1, lm.2, etc

Is there some simple way to create these objects, and name them so that I can easily indicate which data set they correspond to?

Thanks for your help!

  • 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-22T16:38:57+00:00Added an answer on May 22, 2026 at 4:38 pm

    Another approach is to use the plyr package to do the looping. Using the example constructed by @chl, here is how you would do it

    require(plyr)
    
    # read csv files into list of data frames
    data_frames = llply(csvdat, read.csv)
    
    # run regression models on each data frame
    regressions = llply(data_frames, lm, formula = y ~ .)
    names(regressions) = csvdat
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've data which looks something like this. | id | name | depth |
I want to implement a data structure which looks something like this. {{RowID, N1,
This is just a simple question. I've been reading the source of something which
I have a class which looks something like this: public class Test { private
I have two tables which looks something like this Table Queue int ID; string
I have an entity which looks something like this: (I'm coding to the web
I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
I have got an XML document which looks something like this. <Root> <Info>....</Info> <Info>....</Info>
I have an XML document which looks something like this: <meadinkent> <record> <comp_div>MENSWEAR</comp_div> <sty_ret_type>ACCESSORIES</sty_ret_type>
For example, I have a struct which is something like this: struct Test {

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.