- Home
- Interview Questions
- Data Science
If the programmers want the output to be a data frame or a vector, then sapply function is used whereas if a programmer wants the output to be a list then lapply is used. There one more function known as vapply which is preferred over sapply as vapply allows the programmer to specific the output type. The disadvantage of using vapply is that it is difficult to be implemented and more verbose.
Seq_along(6) will produce a vector with length 6 whereas seq(6) will produce a sequential vector from 1 to 6 c( (1,2,3,4,5,6)).
If two vectors with different lengths perform an operation –the elements of the
shorter vector will be re-used to complete the operation. This is referred to as
element recycling.
Example – Vector A <-c(1,2,0,4) and Vector B<-(3,6) then the result of A*B
will be ( 3,12,0,24). Here 3 and 6 of vector B are repeated when computing
the result.
If a developer wants to skip the current iteration of a loop in the code without terminating it then they can use the next statement. Whenever the R parser comes across the next statement in the code, it skips evaluation of the loop further and jumps to the next iteration of the loop.
The two key parameters required to build a scatter plot matrix are formula- A formula basically like ~a+b+c . Each term gives a separate variable in the pairs plots where the terms should be numerical vectors. It basically represents the series of variables used in pairs.
data- It basically represents the dataset from which the variables have to be taken for building a scatterplot.