Skip to Content
Modern R Programming Cookbook
book

Modern R Programming Cookbook

by Jaynal Abedin
October 2017
Beginner to intermediate
236 pages
7h 38m
English
Packt Publishing
Content preview from Modern R Programming Cookbook

How it works…

Inside the if() statement, the test scenario any(is.na(x)) produces TRUE or FALSE depending on the input vector x. If the test scenario is TRUE, then the output will be a line of text There are missing values in x. Now, print the location index of the missing values.

The which() function searches for the position index where is.na(x) is TRUE and returns the value for that position. The cat() function prints the text in the R console. Similar code has been used for the character vector y too. In fact, to check missing values for any input, either numeric or character is.na() works fine. The output will look as follows:

    There are missing values in x    [1] 4 8    There are missing values in x    [1] 3
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R Cookbook, 2nd Edition

R Cookbook, 2nd Edition

JD Long, Paul Teetor

Publisher Resources

ISBN: 9781787129054Supplemental Content