mimiming avatar

R basic, 'for loop' Calculating Leap Year

mimiming

Published: 26 May 2018 › Updated: 26 May 2018R basic, 'for loop' Calculating Leap Year

R basic, 'for loop' Calculating Leap Year

  • Logical meaning 
  1. & - > and
  2. | - > OR
  3. ! - > Not
  1.  
> for(year in 2000:2018){
+   if (year%%4==0 & year%%100!=0 | year%%400==0){
+     result <- paste(year, "is a leap year.")
+     print(result)
+   }
+   else{
+     result <- paste(year, "is not a leap year.")
+     print(result)
+   }
+ }
[1] "2000 is a leap year."
[1] "2001 is not a leap year."
[1] "2002 is not a leap year."
[1] "2003 is not a leap year."
[1] "2004 is a leap year."
[1] "2005 is not a leap year."
[1] "2006 is not a leap year."
[1] "2007 is not a leap year."
[1] "2008 is a leap year."
[1] "2009 is not a leap year."
[1] "2010 is not a leap year."
[1] "2011 is not a leap year."
[1] "2012 is a leap year."
[1] "2013 is not a leap year."
[1] "2014 is not a leap year."
[1] "2015 is not a leap year."
[1] "2016 is a leap year."
[1] "2017 is not a leap year."
[1] "2018 is not a leap year."


 

Leave R basic, 'for loop' Calculating Leap Year to:

Written by

Read more #load0file0r posts


Best Posts From mimiming

We have not curated any of mimiming's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From mimiming