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.

Chapter 3The Fundamentals of RIn This ChapterUsing functions and argumentsMaking code clear and legibleExtending R with user packagesBefore you start discovering the different ways you can use R on your data,you need to know a few more fundamental things about R.In Chapter 2, we show you how to use the command line and work with theworkspace, so if you’ve read that chapter, you can write a simple script and use theprint(), paste(), and readline() functions — at least in the most basic way. Butfunctions in R are more complex than that, so in this chapter we tell you how to getthe most out of your functions.As you add more arguments to your functions and more functions to yourscripts, those scripts can become pretty complex. To keep your code clear — andyourself sane — you can follow the basic organizational principles we cover in thischapter.Finally, much of R allows you to use other people’s code very easily. You canextend R with packages that have been contributed to the R community byhundreds of developers. In this chapter, we tell you where you can find thesepackages and how you can use them in R.Using the Full Power of FunctionsFor every action you want to take in R, you use a function. In this section, weshow you how you can use them the smart way. We start by telling how to usethem in a vectorized way (basically, allow your functions to work on a whole vectorof values at the same time, instead of just a single value). Then we tell you howyou can reach a whole set of functionalities in R functions with arguments. Finally,we tell you how you can save the history of all the commands you’ve used in asession with — you guessed it! — a function.

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

Saved successfully!

Ooh no, something went wrong!