12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Suppose that Granny and Geraldine decide to raise money for the Make-A-Wish Foundation and asked people to make a donation for every basket theymade. Granny requested $120 per basket, and Geraldine asked for $145 perbasket. How do you calculate the total donations that they collected for eachgame?R makes the calculation easy. First, calculate how much each lady earned pergame, as follows:> Granny.money Geraldine.money Granny.money + Geraldine.money[1] 2165 915 770 1010 2820 1665You also could do this in one line, as follows:> baskets.of.Granny * 120 + baskets.of.Geraldine * 145[1] 2165 915 770 1010 2820 1665Controlling the order of the operationsIn the previous example, you used both a multiplication and an additionoperator. As you see from the result, R correctly multiplies all numbers beforeadding them together. For all arithmetic operators, the classic rules for the order ofoperations apply. Calculations are carried out in the following order:1. Exponentiation2. Multiplication and division in the order in which the operators arepresented3. Addition and subtraction in the order in which the operators arepresentedThe mod operator (%%) and the integer division operator (%/%) have the same

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!