# R Language Interview Questions

> > > > > > R Language Interview Questions

##### Determine the output of the following function f(2). b <- 4 f <- function(a) { b <- 3 b^3 + g(a) } g <- function(a) { a*b }
The global variable b has a value of 4. The function f has an argument 2 and the function’s body has the local variable b with the value 3. So function f(2) will return 3^3 + g(2) and g(2) will give the value 2*4 = 8 where 4 is the value of b.
##### Get all the data of the person having maximum salary.
max_salary_person<- subset(data, salary == max(salary))
print(max_salary_person)
##### Now create an output file which will have data of all the people who joined TCS in 2016 with salary more than 300000
temp 300000 &as.Date(DOJ) >as.Date(“2016-01-01”))
write.csv(temp,”output.csv”,row.names = FALSE)
print(new_temp)
##### How to combine multiple vectors in one data frame?
Example.
a<- c(1,2,3,4)
b<- c(“Amit”,”Sumit”,”Gaurav”)
c<- c(“TCS”,”CTS”,”Musigma”)
df<- cbind(a,b,c)
print(df)
##### What is the function of merge() function?
We can merge two data frames by using the merge() function. The data frames must have same column names on which the merging happens.
Example.
df1<- data.frame(id<- c(1:6), name <- c(rep(“Amit”,3), rep(“Sumit”,3))
df2<- data.frame(id<-c(7,8,9), name<- c(rep(“Nitin”,2), rep(“Paplu”,1))
*outer join
merge(x=df1, y=df2, by = “id”, all = TRUE)
This all = TRUE will give you the outer join, so the new data set will have all the value from both the data frame merged on the id