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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:24:02+00:00 2026-06-18T16:24:02+00:00

I am working on a loop coding on R language, and this code involves

  • 0

I am working on a loop coding on R language, and this code involves two functions. If value is radius, period function should be run instead of radius function, and so on.

I coded using my notes from class, but I think it is wrong. I do not get any warnings, but if I do on Console:

R<-98
orbit(R)

I will get this message:

Error in orbit(R) : attempt to apply non-function

This is my function code:

# Two functions: period and radius
# If a value you input is a period (in minutes), radius function should be used (radius(R))
# If a value you input is a radius (in km), period function should be used (period(R))
#   R is radius in km or period in minutes


orbit <- function(R){
    G <-6.673*10^-11
    M <- 5.972*10^24 # in kg

    if(R == 98){
            omega <- 2*pi/R # pr is period for one rotation

            Radi <- (G*M/omega^3)(1/3)
            print(Radi)
        }
    else {

        Peri <- 2*pi*sqrt(R^3/G*M)
        print(Peri)

    }

}

I don’t think I fully understand if and else statement. Does anyone explain it for me? Also what is difference between for statement and if statement?

Thank you for all 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-06-18T16:24:03+00:00Added an answer on June 18, 2026 at 4:24 pm

    The problem in this line

    Radi <- (G*M/omega^3)*(1/3)
    

    where you missing * operation

    if/else statement allows your program to decide which code to execute based on some condition. Like in your code, you have two blocks of code the first one is:

    omega <- 2*pi/R # pr is period for one rotation
    Radi <- (G*M/omega^3)(1/3)
    print(Radi)
    

    which you want to execute only if some condition is true i.e. R == 98, otherwise you execute the other block of code.

    for statement is used when you want to repeatedly execute a block of code many times. Let’s say you want to print the numbers from 1-100, it is not feasible to write print(1) print(2) … 100 times!

    You do this with a simple for loop, e.g.

    for(i in 1:100){
       print(i)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I've been stuck on this do-while loop not working for about two hours.
I have a nice dataset loop working, but I need to run another loop
I am working on a loop like this: int arrA[BIG], arrB[BIG], arrC[BIG]; for(int =
Why is my enhanced loop not working? Vector<String> v = new Vector<String>(); v.add(one); v.add(two);
This is a working snippet of a while loop : while(total_bytes_read != fsize){ while((nread
This is my first post. I started coding when considering a career swap two
I am working with a PHP foreach loop and I need it to output
I'm working with a long running parfor loop in matlab. parfor iter=1:1000 chunk_of_work(iter); end
Possible Duplicate: C# Captured Variable In Loop I'm working on a few simple applications
I'm working on wrapping up the ugly innards of the FindFirstFile / FindNextFile loop

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.