R Language Interview Questions

Avatto > > DATA SCIENTIST > > SHORT QUESTIONS > > R Language Interview Questions

In the while loop the condition is tested and the control goes into the body only when the condition is true
Example
> name <- c(“Pappu”, “John”)
> temp <- 5
> repeat (temp<11){
print(name)
temp <- temp+2
}
The for loop is not limited to integers. You can pass character vectors, logical vectors, lists, or expressions. Example.
>x<- LETTERS[1:2]
for ( i in x) {
print(i)
}
[1] “A”
[2] “B”
Name_of_function<- function(argument_1,argument_2,..) {
function body
}
The argument is the place holder, whenever a function is invoked, it passes a value to the argument. Arguments are optional
Elements in a vector can be sorted using the function sort()
Example.
>temp <- c(3,5,2,6,7,1)
>sort_temp<- sort(temp)
>print(sort_temp)
[1] 1 2 3 5 6 7
>rev_sort<- sort(temp, decreasing = TRUE)
[1] 7,6,5,3,2,1
This function also works with the words
In R, subset() functions help you to select variables and observations while through sample() function you can choose a random sample of size n from a dataset.
**Suppose there is  adata.frame
data_frame_example<- data.frame(a = c(10, 20, 30), b = c(40, 50, 60), c(70, 80, 90))...