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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:19:03+00:00 2026-05-26T21:19:03+00:00

I have a more complicated function that I am working on. I want to

  • 0

I have a more complicated function that I am working on. I want to pass a variable around inside of my function to do several things. The part that is not working is trying to access an object that has my variable’s name embedded in it.

A simple example would be as follows:

    ## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
    ## Page 9: Plant Weight Data.

    ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
    trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
    group <- gl(2,10,20, labels=c("Ctl","Trt"))
    weight <- c(ctl, trt)

    D9.fit.lm <- lm(weight ~ group)

    my.coeff <- function(mname)
       {
        b  <-  round(mname.fit.lm$coef[1],2)
        m  <-  round(mname.fit.lm$coef[2],4)
        r2 <-  round(summary(mname.fit.lm)$r.squared,2)

        cbind(b, m, r2)
       }

So if I try this bit of code like this:

 my.coeff("D9")

Then I get the following error:

 Error in my.coeff("D9") : object 'mname.fit.lm' not found

I really my function to work and it should look like this output

 cbind(round(D9.fit.lm$coef[1],2),round(D9.fit.lm$coef[2],4),round(summary(D9.fit.lm)$r.squared,2))
             [,1]   [,2] [,3]
 (Intercept) 5.03 -0.371 0.07

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-26T21:19:03+00:00Added an answer on May 26, 2026 at 9:19 pm

    Just add this line inside you function

    mname.fit.lm <- get(paste(mname, ".fit.lm", sep = ""))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that I have more trouble getting standard Unix things to run on
Let's have the following simple function (the body of my function is more complicated
In a project that I'm working on I have to work with a rather
I want to write a function that returns the nearest next power of 2
OK, i have a function that compares values and returns the results, regardless of
please help me understand this. You have a function that calls a few methods:
I love jqGrid but sometimes things seem more complicated than they should be. What
I've been working on a rather complicated chart in R. I have a wireframe
I have an array of float values and want the value and more importantly
I have more than one OpenID as I have tried out numerous. As people

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.