Getting ready

The general structure of the if statement in R is as follows:

    if(test_scenario){
valid_R_statements
...
}

From the general structure of the if statement, it is intuitive that if the test scenario produces TRUE, then the statement with curly braces will be executed; otherwise, nothing will happen.

Let’s consider a situation where you have a vector of either numeric or character and you want to check whether there is any missing value or not. If any missing value exists, then you intend to print the position index of the missing value and then the number of the missing value in that input vector. Take a look at the vectors in the following code snippet:

    x <- c(13, 21, 19, NA, 21, 16, 21, NA, 17, 18)
y<- c("Football", "Cricket", NA, "Rugby")
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset