In R, loops are often not the most efficient way to do repetitive calculations. Rather than doing the calculations for each value of a variable it is much more efficient to organize the values of…
The ifelse() function evaluates a logical object (usually a vector-valued logical condition) and returns an object of the same dimension with TRUE values replaced by a value, or vector of values,…