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 6003221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:05:27+00:00 2026-05-23T01:05:27+00:00

Is this possible? I can get mapply to work with the help examples, but

  • 0

Is this possible? I can get mapply to work with the help examples, but I can’t get a trivial example with lm to work. Here’s my attempt which returns a matrix, instead of a list of lm objects.

temp.df <- list(
                data.frame(a = rep(1:10, each = 10), b = 1:100, c = rnorm(100), d = rnorm(100, 2))
                           )
temp.df[[2]] <- subset(temp.df[[1]], a > 2)
temp.mod <- list(a ~ b,
              a ~ b + c,
             a ~ b + c + d)
temp.lm <- mapply(lm, formula = temp.mod, data = temp.df[c(1,1,2)])
temp.sum <- lapply(temp.lm, summary)

Should I just stick with lapply and specifying data = each time? Thanks!

  • 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-23T01:05:28+00:00Added an answer on May 23, 2026 at 1:05 am

    Not sure what you mean by specifying data each time, but if you pack everything into a bigger (nested) list, and write your own wrapper function that calls lm() and summary(), lapply is a good option:

    bigList <-  list(m1=list(dat=temp.df[[1]],mod=temp.mod[[1]]),
                  m1=list(dat=temp.df[[2]],mod=temp.mod[[2]]))
    
    fitLM <- function(x){
    lm1 <- lm(x$mod,data=x$dat)
    return(summary(lm1))
    }
    
    
    temp.lm <- lapply(bigList,FUN=fitLM)
    

    Edit: Just to follow up on the mapply behavior, when I run your code, I get a 12×3 matrix that actually does contain all the relevant lm object information, but the class attribute has been lost. Resetting that and then lapply-ing summary() works with your original code, I believe. But I think a nested list of arguments and lapply() is simpler in this case.

    lmList <- list(a=temp.lm[,1],b=temp.lm[,2],c=temp.lm[,3])
    lmList <- lapply(lmList,function(x){class(x) <- "lm";return(x)})
    temp.sum <- lapply(lmList, summary)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure this is possible, but in ruby, you can dynamically call a
I'm sure this must be possible, but I can't find out how to do
It's quite possible a question like this has been asked before, but I can't
I can't seem to figure out how this is happening. Here's an example of
I hope somebody can help work out to do this. Basically, I have a
Is this possible? I can't find it anywhere.
Is this possible? In an events system an event can have multiple times. (ie,
Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This
If this is possible, please provide a sample query or two so I can
How can I retrieve the current working directory of cmd.exe? This seems possible. For

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.