Explain the usage of which() function in R language.
which() function determines the postion of elemnts in a logical vector that are TRUE. In the below example, we are finding the row number wherein the maximum value of variable v1 is recorded.
mydata=data.frame(v1 = c(2,4,12,3,6))
It returns 3 as 12 is the maximum value and it is at 3rd row in the variable x=v1.
How can you merge two data frames in R language?
Data frames in R language can be merged manually using cbind () functions or by using the merge () function on common rows or columns.View
R programming language has several packages for data science which are meant to solve a specific problem, how do you decide which one to use?
CRAN package repository in R has more than 6000 packages, so a data scientist needs to follow a well-defined process and criteria to select the right one for a specific task. When looking for a package in the CRAN repository a data scientist should list out all the requirements and issues so that an ideal R package can address all those needs and issues.
The best way to answer this question is to look for an R package that follows good software development principles and practices. For example, you might want to look at the quality documentation and unit tests. The next step is to check out how a particular R package is used and read the reviews posted by other users of the R package. It is important to know if other data scientists or data analysts have been able to solve a similar problem as that of yours. When you in doubt choosing a particular R package, I would always ask for feedback from R community members or other colleagues to ensure that I am making the right choice.View
What will be the result of multiplying two vectors in R having different lengths?
The multiplication of the two vectors will be performed and the output will be displayed with a warning message like – “Longer object length is not a multiple of shorter object length.” Suppose there is a vector a<-c (1, 2, 3) and vector b <- (2, 3) then the multiplication of the vectors a*b will give the resultant as 2 6 6 with the warning message. The multiplication is performed in a sequential manner but since the length is not same, the first element of the smaller vector b will be multiplied with the last element of the larger vector a.View
What is the procedure to check the cumulative frequency distribution of any categorical variable?
The cumulative frequency distribution of a categorical variable can be checked using the cumsum () function in R language.
gender = factor(c("f","m","m","f","m","f"))
y = table(gender)
Output of the above R code-
How to check the frequency distribution of a categorical variable?
The frequency distribution of a categorical variable can be checked using the table function in R language. Table () function calculates the count of each categories of a categorical variable.
Output of the above R Code –
Programmers can also calculate the % of values for each categorical group by storing the output in a dataframe and applying the column percent function as shown below -
t = data.frame(table(gender))
t$percent= round(t$Freq / sum(t$Freq)*100,2)
Write the R programming code for an array of words so that the output is displayed in decreasing frequency order.
R Programming Code to display output in decreasing frequency order -
tt <- sort(table(c("a", "b", "a", "a", "b", "c", "a1", "a1", "a1")), dec=T) depth <- 3 tt[1:depth]
1) a a1 b 2) 3 3 2
How will you merge two dataframes in R programming language?
Merge () function is used to combine two dataframes and it identifies common rows or columns between the 2 dataframes. Merge () function basically finds the intersection between two different sets of data.
Merge () function in R language takes a long list of arguments as follows –
Syntax for using Merge function in R language -
merge (x, y, by.x, by.y, all.x or all.y or all )
What is R Base package?
R Base package is the package that is loaded by default whenever R programming environent is loaded .R base package provides basic fucntionalites in R environment like arithmetic calcualtions, input/output.View
What will be the output of the following R programming code ?
It will give an error.View
Can you tell if the equation given below is linear or not ?
Yes it is a linear equation as the coefficients are linear.View
Write a function to extract the first name from the string “Mr. Tom White”.
substr (“Mr. Tom White”,start=5, stop=7)View
How will you combine multiple different string like “Data”, “Science”, “in” ,“R”, “Programming” as a single string “Data_Science_in_R_Programmming” ?
paste(“Data”, “Science”, “in” ,“R”, “Programming”,sep="_")View
What will be the output on executing the following R programming code –
What will be the output of runif (7)?
It will generate 7 randowm numbers between 0 and 1.View
How will you drop variables using indices in a data frame?
Let’s take a dataframe df<-data.frame(v1=c(1:5),v2=c(2:6),v3=c(3:7),v4=c(4:8))
df ## v1 v2 v3 v4 ## 1 1 2 3 4 ## 2 2 3 4 5 ## 3 3 4 5 6 ## 4 4 5 6 7 ## 5 5 6 7 8
Suppose we want to drop variables v2 & v3 , the variables v2 and v3 can be dropped using negative indicies as follows-
df1 ## v1 v4 ## 1 1 4 ## 2 2 5 ## 3 3 6 ## 4 4 7 ## 5 5 8
Write the syntax to set the path for current working directory in R environment.
Which function is used to create a histogram visualisation in R programming language?
How will you list all the data sets available in all R packages?
Using the below line of code-
data(package = .packages(all.available = TRUE))
Which function helps you perform sorting in R language?
© 2017 QuizBucket.org