Avatto>>DATA SCIENTIST>>SHORT QUESTIONS>>R Language Interview Questions
Vectors can be combined from 2 to 1 by using the c() function Example.
> first <- c(1,2,3,4)
> second <- (“a”, “b”, “c”)
> third <- c(first, second)
> print(third)
[1] “1” “2” “3” “4” “a” “b” “c”
The matrix can have only 2 dimensions whereas an array can have as many dimensions as you want. Matrix is defined with the help of data, number of rows, number of columns and whether the elements are to be put in row-wise or column-wise.
In array, you need to give the dimension of the array. An array can be of any number of dimensions and each dimension is a matrix. For example, a 3x3x2 array represents 2 matrices each of dimension 3x3.
A data frame can contain vectors with different inputs and a matrix cannot. (You can have a data frame of characters, integers, and even other data frames, but you can't do that with a matrix. A matrix must be all the same type.)
So, the data frame can have a different vector of character, numbers, logic, etc. and it is still cool. But, for a matrix, you need only one type of data type.
General format is >Temp_matrix< – matrix (vector, nrow=r ,ncol=c , byrow=FALSE, dimnames = list ( char_vector_ rowname, char_vector_colnames))
The repeat loop executes a sequence of statements multiple times. It doesn’t put the condition at the same place where we put the keyword repeat. Example
> name <- c(“Pappu”, “John”)
> temp <- 5
> repeat {print(name)
temp <- temp+2
if(temp > 11) {
break
}
}
So, this will return the name vector 4 times. First, it prints the name and then increase the temp to 7 and so on.


Description