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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:23:22+00:00 2026-05-25T19:23:22+00:00

I got a bunch dynamically created regressions stored in some list called regressions .

  • 0

I got a bunch dynamically created regressions stored in some list called regressions. Now I´d like to rename their coefficients efficiently. What I have so far is this loop that works:

for (i in 1:length(params[,1])){
names(regressions[[i]]$coefficients)[pos] <- paste(params[i,1],".lag",params[i,2],sep="")
}

I’ve been trying for quite a while to get this done a little more generally with the help of a function, cause this not the only list of regressions I have. However I could not get anything else to work. Here a few other tries basically based on lapply:

 correctNames <- function(reglist,namevec,pos){
 names(reglist[[i]]$coefficients)[pos] <- as.character(namevec)
}

lapply(regressions,correctNames(reglist,namevec,pos),
reglist=regressions,namevec=params[,1],pos=2)

Another try was to write a function with a for loop which also works internally as print shows but does not assign the names globally (where the regressions list is stored).

correctNames <- function(reglist,pos,namevec){
for (i in 1:length(params[,1])){
names(reglist[[i]]$coefficients)[pos] <- paste(namevec,".lag",namevec,sep="")
}
#this test proves it's work inside the function... 
print(reglist[[10]]
}

Ah, gimme a break.

  • 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-25T19:23:22+00:00Added an answer on May 25, 2026 at 7:23 pm

    There’s no “i” inside that first version of “correctNames” function; and you probably don’t realize that you are not assigning it to “regressions”, only to a copy of the regression object. Try instead:

    correctNames <- function(reglist,namevec,pos){
      names(reglist$coefficients)[pos] <- as.character(namevec)
       return(reglist)                          }
    newregs <- mapply(correctNames,  
                         reglist=regressions, 
                         namevec=as.character(params[,1]), 
                         MoreArgs= list( pos=2))
    

    After seeing the note from Ramnath and noticing that the code did work but was giving flaky names for the “params” I looked at params and saw that it was a factor, and so changed the argument in the mapply call to as.character(params[,1]).

    > newregs[1,1]
    [[1]]
    (Intercept)     log(M1) 
      -5.753758    2.178137 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created some code that will dynamically generate a bunch of different LinkButtons. I've
I've got a bunch of queues stored in the global globqueue array. I now
I've got a bunch of servers running this Linux app. I'd like for them
I've got a bunch of strings like: Hello, here's a test colon&#58;. Here's a
I got bunch of LI elements animating (slideDown) inside UL. After LI finish their
I've got a bunch of really big files that contain lines like: convert ./1776/07/04/T915002.tif
I've got a bunch of XHR actions in a controller, which return some HTML
I'm got a bunch of html code like this: <a href=http://example.com/project-a title=Project A (test)>Project
I've got a page with a bunch of little forms. I want to dynamically
I've got bunch of shell scripts that used some command and other tools. So

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.