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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started