CHAPTER 17

image

Tricks of the Trade

This book would not be complete without advice on some tricky parts of R. When it seems that everything is set up right, but things still do not do what you expect and you do not know why, this chapter can help. This chapter also describes some not-so-obvious parts of R.

Value Substitution: NA, NaN, Inf, and -Inf

This section has to do with missing data (NA) or illegal elements (NaN, Inf, or -Inf). Say you want to substitute a value, for example 0, for missing values. The intuitive approach would be to enter something like the following:

mat[ mat==NA ] = 0

This does not work. What does work is to enter the following: ...

Get R Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.