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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:58:06+00:00 2026-05-23T05:58:06+00:00

Is there a function that can extract two or more columns from a coeftest

  • 0

Is there a function that can extract two or more columns from a coeftest object? This is easy one coeftest object at a time, but can I do the same to a list (other than a for() loop)?

> # meaningless data
> temp <- data.frame(a = rnorm(100, mean = 5), b = rnorm(100, mean = 1),
+                    c = 1:100)
> formulas <- list(a ~ b, a ~ c)
> models <- lapply(formulas, lm, data = temp)
> library(lmtest)
> cts <- lapply(models, coeftest)

> # easy to extract columns one object at a time
> cts[[1]][, 1:2]
              Estimate Std. Error
(Intercept)  5.0314196  0.1333705
b           -0.1039264  0.0987044

> # but more difficult algorithmically
> # either one column
> lapply(cts, "[[", 1)
[[1]]
[1] 5.03142

[[2]]
[1] 5.312007

> # or two
> lapply(cts, "[[", 1:2)
Error in FUN(X[[1L]], ...) : attempt to select more than one element

Maybe the more fundamental question is if there is a way to turn the meat of the coeftest object into a data frame, which would allow me to extract columns singly, then use mapply(). Thanks!

Edit: I would like to end up with a matrices (or data frames) with the first and second columns.

    [[1]]
              Estimate Std. Error
(Intercept)  5.0314196  0.1333705
b           -0.1039264  0.0987044

[[2]]
                Estimate  Std. Error
(Intercept)  5.312007153 0.199485363
c           -0.007378529 0.003429477
  • 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-23T05:58:07+00:00Added an answer on May 23, 2026 at 5:58 am

    [[ is the wrong subset function in this case. Note that when you lapply() over a list, what you are operating on are the components of the list, the bits you would get with list[[i]] where i is the ith component.

    As such, you only need the [, 1:2] bit of cts[[1]][, 1:2] in the lapply() call. It is a little bit trickier because of the arguments for [, but easily doable with lapply():

    > lapply(cts, `[`, , 1:2)
    [[1]]
                    Estimate Std. Error
    (Intercept)  4.926679544  0.1549482
    b           -0.001967657  0.1062437
    
    [[2]]
                   Estimate  Std. Error
    (Intercept) 4.849041327 0.204342067
    c           0.001494454 0.003512972
    

    Note the <space>, before 1:2; this is the equivalent of [ , 1:2].

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

Sidebar

Related Questions

As title; is there any function that can achieve this?
Is there a built-in function/method that can check if a given string is a
Is there a way that I can create a function that takes an int
Is there code in VBA I can wrap a function with that will let
Is there any function that converts an escaped Url string to its unescaped form?
In .NET is there a function that tests if a string is syntactically a
in .NET is there a function that returns the root letter (the letter without
Is there a POSIX function that will give me the size of a directory
There's an existing function that ends in the following, where d is a dictionary:
Is there a C library function that will return the index of a character

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.