Hands-On Programming with R by Garrett Grolemund
Author:Garrett Grolemund
Language: eng
Format: epub, pdf
ISBN: 9781449359010
Publisher: O'Reilly Media
Published: 2014-03-15T00:00:00+00:00
if (num < 0) { num <- num * -1 }
If num < 0 is TRUE, R will multiply num by negative one, which will make num positive:
num <- -2 if (num < 0) { num <- num * -1 } num ## 2
If num < 0 is FALSE, R will do nothing and num will remain as it is—positive (or zero):
num <- 4 if (num < 0) { num <- num * -1 } num ## 4
The condition of an if statement must evaluate to a single TRUE or FALSE. If the condition creates a vector of TRUEs and FALSEs (which is easier to make than you may think), your if statement will print a warning message and use only the first element of the vector. Remember that you can condense vectors of logical values to a single TRUE or FALSE with the functions any and all.
You don’t have to limit your if statements to a single line of code; you can include as many lines as you like between the braces. For example, the following code uses many lines to ensure that num is positive. The additional lines print some informative statements if num begins as a negative number. R will skip the entire code block—print statements and all—if num begins as a positive number:
Download
Hands-On Programming with R by Garrett Grolemund.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Biomathematics | Differential Equations |
Game Theory | Graph Theory |
Linear Programming | Probability & Statistics |
Statistics | Stochastic Modeling |
Vector Analysis |
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6200)
Weapons of Math Destruction by Cathy O'Neil(5778)
Factfulness: Ten Reasons We're Wrong About the World – and Why Things Are Better Than You Think by Hans Rosling(4454)
Descartes' Error by Antonio Damasio(3137)
A Mind For Numbers: How to Excel at Math and Science (Even If You Flunked Algebra) by Barbara Oakley(3075)
Factfulness_Ten Reasons We're Wrong About the World_and Why Things Are Better Than You Think by Hans Rosling(3025)
TCP IP by Todd Lammle(2982)
Applied Predictive Modeling by Max Kuhn & Kjell Johnson(2857)
Fooled by Randomness: The Hidden Role of Chance in Life and in the Markets by Nassim Nicholas Taleb(2833)
The Tyranny of Metrics by Jerry Z. Muller(2818)
The Book of Numbers by Peter Bentley(2744)
The Great Unknown by Marcus du Sautoy(2516)
Once Upon an Algorithm by Martin Erwig(2454)
Easy Algebra Step-by-Step by Sandra Luna McCune(2433)
Lady Luck by Kristen Ashley(2386)
Practical Guide To Principal Component Methods in R (Multivariate Analysis Book 2) by Alboukadel Kassambara(2357)
Police Exams Prep 2018-2019 by Kaplan Test Prep(2332)
All Things Reconsidered by Bill Thompson III(2241)
Linear Time-Invariant Systems, Behaviors and Modules by Ulrich Oberst & Martin Scheicher & Ingrid Scheicher(2210)
