Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!