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.

all(). To find out whether Granny was always better than Geraldine, use thefollowing code:> all(the.best)[1] FALSEStill, Granny rocks a bit.You can use the argument na.rm=TRUE in the functions all() and any() aswell. By default, both functions return NA if any value in the vector argument ismissing (see “Dealing with missing values,” earlier in this chapter).Powering Up Your Math with Vector FunctionsAs we suggest throughout this chapter, vectorization is the Holy Grail for everyR programmer. Most beginners struggle a bit with that concept becausevectorization isn’t one little trick, but a way of coding. Using the indices andvectorized operators, however, can save you a lot of coding and calculation time —and then you can call a gang of power functions to work on your data, as we showyou in this section.Why are power functions so helpful? Maybe you’re like us: We’re lazy andimpatient enough to try to translate our code into “something with vectors” asoften as possible. We don’t like to type too much, and we definitely don’t like towait for the results. If you can relate, read on.Using arithmetic vector operationsA third set of arithmetic functions consists of functions in which the outcome isdependent on more than one value in the vector. Summing a vector with the sum()function is such an operation. You find an overview of the most important functionsin Table 4-5.Table 4-5 Vector Operations

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

Saved successfully!

Ooh no, something went wrong!