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.

For the logarithms with bases 2 and 10, you can use the conveniencefunctions log2() and log10().You carry out the inverse operation of log() by using exp(). This last functionraises e to the power mentioned between brackets, like this:> x exp(x)Again, you can add a vector as an argument, because the exp() function isalso vectorized. In fact, in the preceding code, you constructed the vector withinthe call to exp(). This code is yet another example of nesting functions in R.Putting the science in scientific notationThe outcome of the last example may look a bit weird if you aren’t familiarwith the scientific notation of numbers. Scientific notation allows you to represent avery large or very small number in a convenient way. The number is presented as adecimal and an exponent, separated by e. You get the number by multiplying thedecimal by 10 to the power of the exponent. The number 13,300, for example, alsocan be written as 1.33 × 10^4, which is 1.33e4 in R:> 1.33e4[1] 13300Likewise, 0.0412 can be written as 4.12 × 10^–2 , which is 4.12e-2 in R:> 4.12e-2[1] 0.0412R doesn’t use scientific notation just to represent very large or very smallnumbers; it also understands scientific notation when you write it. You can usenumbers written in scientific notation as though they were regular numbers, likeso:> 1.2e6 / 2e3[1] 600R automatically decides whether to print a number in scientific notation. Its

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

Saved successfully!

Ooh no, something went wrong!