Skip to Content
Data Analysis with R, Second Edition - Second Edition
book

Data Analysis with R, Second Edition - Second Edition

by Tony Fischetti
March 2018
Beginner to intermediate content levelBeginner to intermediate
570 pages
13h 42m
English
Packt Publishing
Content preview from Data Analysis with R, Second Edition - Second Edition

Arithmetic and assignment

Check out the following example:

  > 2 + 2 
  [1] 4 
 
  > 9 / 3 
  [1] 3 
 
  > 5 %% 2    # modulus operator (remainder of 5 divided by 2) 
  [1] 1 

Anything that occurs after the octothorpe or pound sign, #, (or hash-tag for you young'uns), is ignored by the R interpreter. This is useful to document the code in natural language. These are called comments.

In a multi-operation arithmetic expression, R will follow the standard order of operations from math. In order to override this natural order, you have to use parentheses flanking the sub-expression that you'd like to be performed first:

   > 3 + 2 - 10 ^ 2        # ^ is the exponent operator 
   [1] -95 
   > 3 + (2 - 10) ^ 2 
   [1] 67 

In practice, almost all compound expressions are split up with intermediate ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Exploratory Data Analysis with R

Hands-On Exploratory Data Analysis with R

Radhika Datar, Harish Garg
Bayesian Data Analysis, Third Edition, 3rd Edition

Bayesian Data Analysis, Third Edition, 3rd Edition

Andrew Gelman, John B. Carlin, Hal S. Stern, David B. Dunson, Aki Vehtari, Donald B. Rubin
R: Data Analysis and Visualization

R: Data Analysis and Visualization

Tony Fischetti, Brett Lantz, Jaynal Abedin, Hrishi V. Mittal, Bater Makhabel, Edina Berlinger, Ferenc Illés, Milán Badics, Ádám Banai, Gergely Daróczi, Barbara Dömötör, Gergely Gabler, Dániel Havran, Péter Juhász, István Margitai, Balázs Márkus, Péter Medvegyev, Julia Molnár, Balázs Árpád Szucs, Ágnes Tuza, Tamás Vadász, Kata Váradi, Ágnes Vidovics-Dancs

Publisher Resources

ISBN: 9781788393720Supplemental Content