Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

R language problem use R to 1. Write a function that takes a number year and returns a logical value which is either TRUE, if

R language problem

use R to

1. Write a function that takes a number year and returns a logical value which is either TRUE, if the year was or will be a leap year, or FALSE if not. The rule for determining leap years is that one of the following conditions must hold:

1) the year is divisible by 4 but not divisible by 100, or 2) the year is divisible by 400.

Now write an R expression using your function to calculate how many leap years you have lived through during your lifetime.

here is my code:

leap year <-function(year) {

count <- 0

for (x in year) { if ((x %% 4 == 0 & x %% 100 != 0) | (x %% 400 ==0)) { return(TRUE) count <- count +1

} else { return (FALSE) } } } leapyear(1996:2016)

It only plugs 1996 in the loop; however, I need to know how many leap years are there from 1996-2016.

please notify the place where I make mistakes.

Thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

An Introduction to the Mathematics of financial Derivatives

Authors: Salih N. Neftci

2nd Edition

978-0125153928, 9780080478647, 125153929, 978-0123846822

More Books

Students also viewed these Mathematics questions

Question

Percent Yield Calculation

Answered: 1 week ago

Question

What is Ramayana, who is its creator, why was Ramayana written?

Answered: 1 week ago