linkedin-skill-assessments-quizzes

R (Programming Language)

Q1. How does a matrix differ from a data frame?

Q2. What value does this statement return?

unclass(as.Date("1971-01-01"))

Q3. What do you use to take an object such as a data frame out of the workspace?

Q4. Review the following code. What is the result of line 3?

xvect<-c(1,2,3)
xvect[2] <- "2"
xvect

Q5. The variable height is a numeric vector in the code below. Which statement returns the value 35?

Q6. In the image below, the data frame is named rates. The statement sd(rates[, 2]) returns 39. As what does R regard Ellen’s product ratings?

Image

Q7. Which choice does R regard as an acceptable name for a variable?

Q8. What is the principal difference between an array and a matrix?

Q9. Which is not a property of lists and vectors?

Q10. In the image below, the data frame on lines 1 through 4 is named StDf. State and Capital are both factors. Which statement returns the results shown on lines 6 and 7?

Image

Q11. Which function displays the first five rows of the data frame named pizza?

Q12. You accidentally display a large data frame on the R console, losing all the statements you entered during the current session. What is the best way to get the prior 25 statements back?

Q13. d.pizza is a data frame. It’s a column named temperature contains only numbers. If you extract temperature using the [] accessors, its class defaults to numeric. How can you access temperature so that it retains the class of data.frame?

> class( d.pizza[ , "temperature" ] )
> "numeric"

Q14. What does c contain?

a <- c(3,3,6.5,8)
b <- c(7,2,5.5,10)
c <- a < b

Q15. Review the statements below. Does the use of the dim function change the class of y, and if so what is y’s new class?

> y <- 1:9
> dim(y) <- c(3,3)

Q16. What is mydf$y in this code?

mydf <- data.frame(x=1:3, y=c("a","b","c"), stringAsFactors=FALSE)

Q17. How does a vector differ from a list?

Q18. What statement shows the objects on your workspace?

Q19. What function joins two or more column vectors to form a data frame?

Q20. Review line 1 below. What does the statement in line 2 return?

1 mylist <- list(1,2,"C",4,5)
2 unlist(mylist)

Q21. What is the value of y in this code?

x <- NA
y <- x/1

Q22. Two variable in the mydata data frame are named Var1 and Var2. How do you tell a bivariate function, such as cor.test, which two variables you want to analyze?

Q23. A data frame named d.pizza is part of the DescTools package. A statement is missing from the following R code and an error is therefore likely to occur. Which statement is missing?

library(DescTools)
deliver <- aggregate(count,by=list(area,driver), FUN=mean)
print(deliver)

Q24. How to name rows and columns in DataFrames and Matrices F in R?

Q25. Which set of two statements-followed by the cbind() function-results in a data frame named vbound?

v1<-list(1,2,3)
v2<-list(c(4,5,6))
vbound<-cbind(v1,v2)
v1<-c(1,2,3)
v2<-list(4,5,6))
vbound<-cbind(v1,v2)
v1<-c(1,2,3)
v2<-c(4,5,6))
vbound<-cbind(v1,v2)

Q26. ournames is a character vector. What values does the statement below return to Cpeople?

Cpeople <- ournames %in% grep("^C", ournames, value=TRUE)

Q27. What is the value of names(v[4])?

v <- 1:3
names(v) <- c("a", "b", "c")
v[4] <- 4

Q28. Which of the following statements doesn’t yield the code output below. Review the following code. What is the result of line 3?

x <- c(1, 2, 3, 4)
Output: [1] 2 3 4

Q29. Given DFMerged <- merge(DF1, DF2) and the image below, how many rows are in DFMerged?

image

Q30. What does R return in response to the final statement?

x<-5:8
names(x)<-letters[5:8]
x

Q31. How do you return “October” from x in this code?

x<-as.Date("2018-10-01")

Q32. How will R respond to the last line of this code?

fact<-factor(c("Rep","Dem","Dem","Rep"))
fact
[1] Rep Dem Dem Rep
Levels: Rep Dem
fact[2]<-"Ind"

Q33. What does R return?

StartDate<- as.Date("2020/2/28")
StopDate<- as.Date("2020/3/1")
StopDate-StartDate

Q34. What does the expression mtrx * mtrx do ?

> mtrx <- matrix( c(3,5,8,4), nrow= 2,ncol=2,byrow=TRUE)
> newmat <- mtrx * mtrx
> newmat
     [,1] [,2]
[1,]    9   25
[2,]   64   16

# The `%*%` operator gives matrix multiplication
> mtrx %*% mtrx
     [,1] [,2]
[1,]   49   35
[2,]   56   56

Q35. Which function in R combines different values into a single object?

Q36. Which file contains settings that R uses for all users of a given installation of R?

Q37. If mdf is a data frame, which statement is true ?

Q38. A list can contain a list as an element. MyList has five columns, and the third column’s item is a list of three items. How do you put all seven values in MyList into a single vector?

Q39. Which strings could be returned by the function ls(path = “^V”)?

Q40. StDf is a data frame. Based on this knowledge, what does this statement return?

StDf[, -1]

Q41. Which statement enables you to interactively open a single file?

Q42. How are these data types alike: logical, integer, numeric, and character?

Q43. What does the MyMat[ ,3] subsetting operation return for this code?

MyMat = matrix(c(7, 9, 8, 6, 10, 12),nrow=2,ncol=3, byrow = TRUE)
[ ,3]
[1, ] 8
[2, ] 12
[1] 8 12
[1] 10 12
[ ,3]
[1, ] 10
[2, ] 12

Q44. What does the function power.anova.test return?

Q45. Review the statement below. What is the effect of covariate:factor on the analysis?

result <- lm(outcome ~ covariate + factor + covariate:factor, data = testcoef)
# Example call to demonstrate.  `Species` is a Factor.  Petal.Length, Petal.Width are numeric.
# see `help(formula)` for more details on the formula specification.  `:` is "effect modification" or "interaction"

> summary(lm(Petal.Length ~ Petal.Width + Species + Petal.Width:Species, data = iris))
...
Petal.Width:Speciesversicolor   1.3228     0.5552   2.382   0.0185 *
Petal.Width:Speciesvirginica    0.1008     0.5248   0.192   0.8480
...

Q46. A variable whose type is numeric can contain which items?

Q47. What is the legitimate name of a data class in R?

Q48. How do you extract the values above the main diagonal from a square matrix named Rmat?

Q49. x is a vector of type integer, as shown on line 1 below. What is the type of the result returned by the statement > median(x)?

x <- c(12L, 6L, 10L, 8L, 15L, 14L, 19L, 18L, 23L, 59L)

Q50. A list named a is created using the statement below. Which choice returns TRUE?

a <- list("10", TRUE, 5.6)

Q51. How do you obtain the row numbers in a data frame named pizza for which the value of pizza$delivery_min is greater than or equal to 30?

late_delivery <- pizza$delivery_min >= 30
index_late <- index(late_delivery)
index_late
late_delivery <- pizza$delivery_min >= 30
rownum_late <- rownum(late_delivery)
rownum_late
late_delivery <- pizza$delivery_min >= 30
which_late <- which(late_delivery)
which_late
late_delivery <- pizza$delivery_min >= 30
late <- piza$late_delivery
pizza$late

Q52. Which function returns [1] TRUE FALSE TRUE?

indat <- c("Ash Rd","Ash Cir","Ash St")

Q53. Which statement returns the fourth row of a data frame named fish?

Q54. What is the value of csum?

a <- c(1.2, 2, 3.5, 4)
b <- c(1.2, 2.2, 3.5, 4)
csum <-sum(a == b)

Q54. A list named a is created using the statement below. Which choice returns TRUE?

a <- list("10", TRUE, 5.6)

Q55. What is the result of these three lines of code?

vect1 <- c(1:4)
vect2 <- c(1:2)
vect1 * vect2

Q56. Which choice returns [1] “2019-09-28”?

Q57. The variable potus is a character vector, as shown in line 1 below. Wich statement returns the results shown?

1 potus <- c("GHW Bush", "Clinton", "GW Bush", "Obama")

Results: [1] "GHW BUsh" "Clinton" "Obama"

Q58. A data frame contains two factor -fact1 and fact2- and a numerical outcome variable. Which statement returns results that do NOT include an interaction term?

Q59. Review line 1 below. What does the statement on line 2 return?

1 myvect <- c(-2,-1,0)
2 as.logical(myvect)

Q60. Which option setting can cause difficulty if you want to add to a variable’s possible values after you have designed an object’s initial data structure?

Q61. In this image below, the data frame on lines 1 through 4 is named StDf. StDf contains no factors. Why does statement on line 6 return “character” while the statement on line 7 returns “data.frame”?

image

Q62. Review line 1. What does the statement on line 3 return?

mtrx <- matrix(1:6, 3, 2)

mtrx[, -1]

image

Q63. Why does sum(!is.na(pizza$week)) return the number of rows with valid, non-NA values in the column named week?

Q64. How do you get documentation of an installed and loaded R package named dplyr and packages with dplyr as an alias?

Q65. In the image below, the data frame named iris includes a numeric vector named Petal.Length. Do the functions labeled Pair 1 and Pair 2 return the same information?

image

Q66. The _ for R are the main feature that make it different from the original S language.

reference

Q67. Which of the following is a base package for R programming ?

reference

Q68. What is the primary purpose of the apply() function family in R?

reference

Q69. Which function is used to read CSV files in R?

reference

Q70. What does the str() function do in R?

reference

Q71. In R, what is the difference between <- and = for assignment?

reference

Q72. What does the library() function do?

reference

Q73. Which of the following statements about factors in R is TRUE?

reference

Q74. What does the subset() function return?

reference

Q75. In R, what is the purpose of the with() function?

reference

Q76. What is the output of typeof(5L) in R?

reference

Q77. Which function is used to calculate the standard deviation in R?

reference

Q78. What does the na.omit() function do?

reference

Q79. In R, what is a tibble?

reference

Q80. What does the seq() function generate?

reference

Q81. Which operator is used for matrix multiplication in R?

reference

Q82. What is the purpose of set.seed() in R?

reference

Q83. What does nrow() return for a vector?

reference

Q84. Which function is used to transpose a matrix in R?

reference

Q85. What is the default behavior of read.csv() regarding string columns?

reference

Q86. What does the %>% operator do in R?

reference

Q87. Which function converts a character string to a Date object in R?

reference

Q88. What is the result of rep(1:3, times=2)?

reference

Q89. What does names() function return for a vector?

reference

Q90. Which function is used to sort a vector in descending order?

reference

Q91. What does the table() function do in R?

reference

Q92. In R, what is the purpose of the ifelse() function?

reference

Q93. What does length(NULL) return?

reference

Q94. Which function is used to calculate the correlation between two variables?

reference

Q95. What is the output of class(matrix(1:6, 2, 3))?

reference

Q96. Which function is used to find unique elements in a vector?

reference

Q97. What does lapply() return?

reference

Q98. In R, what is the purpose of the aggregate() function?

reference

Q99. What does is.na(c(1, NA, 3)) return?

reference

Q100. Which function is used to calculate the mean of each column in a data frame?

reference

Q101. What does the paste() function do?

reference

Q102. In R, what is the difference between sapply() and lapply()?

reference

Q103. What does dim() return for a vector of length 10?

reference

Q104. Which function is used to read an R script file?

reference

Q105. What is the output of all(c(TRUE, TRUE, FALSE))?

reference

Q106. Which function creates a sequence from 1 to 10 with increments of 0.5?

reference

Q107. What does match(c("a", "b"), c("b", "c", "a")) return?

reference

Q108. In R, what is the purpose of the merge() function?

reference

Q109. What does range(c(5, 2, 8, 1, 9)) return?

reference

Q110. Which function is used to calculate the median in R?

reference

Q111. What is the result of any(c(FALSE, FALSE, TRUE))?

reference

Q112. What does head(df, n=-5) return?

reference

Q113. Which function is used to split data into groups in R?

reference

Q114. What does rev(1:5) return?

reference

Q115. In R, what is the purpose of attach()?

reference

Q116. What does nchar("Hello") return?

reference

Q117. Which function is used to calculate the sum of each row in a matrix?

reference

Q118. What does duplicated(c(1, 2, 2, 3)) return?

reference

Q119. What is the output of toupper("hello")?

reference

Q120. Which function is used to create a histogram in base R?

reference