12.07.2015 Views

R dummies

R dummies

R dummies

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Operator Description Examplex + y y added to x 2 + 3 = 5x – y y subtracted from x 8 – 2 = 6x * y x multiplied by y 3 * 2 = 6x / y x divided by y 10 / 5 = 2x ^ y (or x ** y) x raised to the power y 2 ^ 5 = 32x %% y remainder of x divided by y (x mod y) 7 %% 3 = 1x %/% y x divided by y but rounded down (integer divide) 7 %/% 3 = 2All these operators are vectorized. Chapter 3 shows the use of a vectorizedfunction with the paste() function, and the process works exactly the same waywith operators. By using vectorized operators, you can carry out complexcalculations with minimal code.To see how this works, consider these two vectors, which we first discuss inthe All-Star Grannies example in Chapter 3. One vector represents the number ofbaskets Granny made during the six games of the basketball season, and the otherone represents the number of baskets her friend Geraldine made:> baskets.of.Granny baskets.of.Geraldine

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

Saved successfully!

Ooh no, something went wrong!