Do you know that? 77% of Upwork-Elance freelancers have a college degree next

Contact Email: teammmrem@yahoo.com

<< All Upwork (oDesk) and Elance Tests << Elance test answers << Fin. & Mgt. category

Test answers for R 2016

(95) Last updated: February 12
Elance • Fin. & Mgt.
Questions and answers are regularly updated. Answered and not answered tests questions.

This helps getting job: Hundreds of (cover letter examples , interview questions , profile samples ) • Earn on Upwork (oDesk)
Job assistance: jobs popularityfreelance rates

Popular test answers: HTML, .Net, CSS, English, SEO, Photoshop, iOS, Java, Android, Ruby, Python, JavaScript

See all 6 tests answers updated

Find Upwork (oDesk) and Elance test answers on this website:



Collapse | Expand

95 Answered Test Questions:

1. Which R function fits a simple linear regression model of x predicting y?

Answers:

• lm(y ~ x)

• lm(x ~ y)

• proc reg; model y=x; run;

• regress y x

2. What does the following R code output? Y <- c(1,2,3); X <- rep(c(1,length(Y)), times=2); X

Answers:

• 1 3 1 3

• 1 1

• 1 1 3 3

• 1 2 1 2

3. Which R function provides a histogram of the numeric vector X?

Answers:

• plot X

• hist(X)

• plot(X)

• plot.hist(X)

4. What's the output for command : rep(c(1:2), times = 3)

Answers:

• 1 2 1 2 1 2

• 1:2 1:2 1:2

• 3 6 9

• 1 1 1 2 2 2

5. Which R function imports a comma separated file "X.csv"?

Answers:

• read("X.csv")

• import("X.csv")

• read.csv("X.csv")

• import.csv("X.csv")

6. What's the output for command: print("Hello World")

Answers:

• OMG

• Hello World

• 2

• NA

7. What does the following R code output? seq(2,10, by=2)

Answers:

• 2 4 6 8 10

• 1 3 5 7 9

• 2

• 2 10

8. Given the command: Z <- array(h, dim=c(3,4,2)), dim(Z) stands for:

Answers:

• the dimension vector c(3,4,2)

• the array of all zeros

• the data vector as it was in h

• the entire array as an array

9. Which R code will sort the vector X <- c(1,5,3,9,7) from largest to smallest?

Answers:

• sort(X, decreasing=T)

• X[sort(X)]

• order(X)

• sort(X)

10. What's the value of x after command: x <- 3 < 4

Answers:

• 4

• FALSE

• TRUE

• 3

11. In the R data set X, what value will missing numeric data be assigned? X <- read.csv("X.csv")

Answers:

• NA

• 999

• .

• "missing"

12. In order to apply lag operator for the data, you should:

Answers:

• convert the data into matrices

• convert the data into the time-series object

• convert the data into integer

• convert the data into vector

13. Which R function provides basic descriptive summary statistics for a numeric vector x?

Answers:

• proc contents x;

• summarize(x)

• summary(x)

• summarize x

14. The entities on which R operates are technically known as:

Answers:

• objects

• commands

• events

• mode

15. What's the output for command is.nan(0/0)

Answers:

• TRUE

• FALSE

• -Inf

• NA

16. How does one obtain the FIRST element of x when x = 1:9?

Answers:

• x$0

• x[0]

• x$1

• x[1]

17. What is an appropriate syntax for a 'for' loop in R to run specific simulation code nnn times?

Answers:

• for(i=1, nnn, 1) { <simulation code> }

• for i in 1:nnn: <simulation code>

• for(i in 1:nnn) { <simulation code> }

• for(i - nnn) { <simulation code> }

18. Which command is used to test if an object is a time series?

Answers:

• is.ts

• if.ts

• as.ts

• ts

19. In the plot( ) function, what option is used to specify that the x-axis displays values from 0 to 1?

Answers:

• xlim=c(0, 1)

• xlim="0, 1"

• xlimit="0, 1"

• xlab=c(0, 1)

20. What does the following R function output? abs(10 - 3 * 4)

Answers:

• 2

• NA

• -2

• 0

21. What is the output of the following R code? x<-2; y <- c(1:3); paste("The value of x is", x, "and the value of y[x] is", y[x], sep=" ")

Answers:

• "The value of x is 2 and the value of y[x] is 2"

• "The value of x is 2 and the value of y[x] is c(1:3)[2]"

• "The value of x is 2 and the value of y[x] is 6"

• "The value of x is 2 and the value of y[x] is 4"

22. Which of the following is NOT a valid data import function?

Answers:

• read.table

• readdata

• read.csv

• scan

23. What's the value of 'ind' after running command : z <- c(1:3,NA);  ind <- is.na(z)

Answers:

• FALSE

• FALSE TRUE

• TRUE

• FALSE FALSE FALSE TRUE

24. What's the output for command: paste("O", "M", "G", sep = "")?

Answers:

• "omg"

• "O" "M" "G"

• "OMG"

• "O M G"

25. Suppose numeric vectors X, Y, and Z are all of the same length. Which R command will create a matrix with rows X, Y, Z?

Answers:

• matrix(X, Y, Z, nrow=3)

• matrix(rbind(X, Y, Z), nrow=3)

• matrix(cbind(X, Y, Z), nrow=3)

• matrix(rbind(X, Y, Z), ncol=3)

26. What R function can be used to tabulate values of categorical variable Y (columns) by categorical variable X (rows)?

Answers:

• table(X, Y)

• table(X*Y)

• tabulate(X, Y)

• table(Y ~ X)

27. What is the value of Y? X <- c(1,2,2,2,3,3,4,4,5,6); Y <- unique(X[which(X<4)])

Answers:

• 1 2 2 2 3 3

• 1 2 3

• 3

• 1 2 3 4

28. In order to decide the inequality between x and y, you can use the command:

Answers:

• x == y

• x =! y

• x =~ y

• x != y

29. Which R function adds a line with slope 1 and intercept 0 into an existing plot of Y versus X?

Answers:

• lty=c(0, 1)

• lines(0, 1)

• abline(0, 1)

• smooth.spline(0, 1)

30. What's the output for command: seq(from = 1, to = 5, by = 3)

Answers:

• 1 4 7

• 1 4

• 1 2 3 4 5

• 1 3 5

31. What's the output for command:  paste0("O", "M", "G")?

Answers:

• "omg"

• "O M G"

• "O" "M" "G"

• "OMG"

32. What does the option 'cex' do in the following R function? text(0, 1, "Hello", cex=2)

Answers:

• Surpresses printing of the word "Hello"

• Prints the word "Hello" in bold font

• Increases the size of the word "Hello" by a factor of 2

• Right justifies the word "Hello"

33. Which R function will generate a mean for each row in a numeric matrix X with intermittent missing values?

Answers:

• by(X, 1, mean, na.rm=T)

• apply(X, 1, mean, na.rm=T)

• mean(X[1:length(X[,1]),], na.rm=T)

• apply(X, 1, mean)

34. What is the output of the following R function? yyy <- c(1, 3, NA); fff <- function(xxx) {mean(xxx)}; fff(yyy)

Answers:

• 2

• 1.5

• NULL

• NA

35. Which is NOT a valid R function for obtained the residuals from a simple linear regression model of X predicting Y?

Answers:

• lm(Y ~ X)$residuals

• residuals(lm(Y ~ X))

• Y - lm(Y - X)$fitted.values

• lm(Y ~ X)$residuals - lm(Y ~ X)$fitted.values

36. In a linear regression model with outcome y and linear predictors x1, x2, and x3, which R code correctly includes an interaction term between x1 and x2?

Answers:

• lm(y ~ x1:x2 + x3)

• lm(y ~ x1:x3 + x1:x2)

• lm(y ~ x1 + x2 + x3 + x1*x2)

• lm(y ~ x1 + x2 + x3 + interaction(x1, x2))

37. Which command is correct in order to load excel file into R?

Answers:

• d<-load.table("c:/ceo.csv",header=TRUE,sep=",",na.string=".")

• d<-read.table("c:/ceo.csv",header=TRUE,sep=",",na.string=".")

• d<-read("c:/ceo.csv",header=TRUE,sep=",",na.string=".")

• d<-load("c:/ceo.csv",header=TRUE,sep=",",na.string=".")

38. What is the value of Y? Y <- 10 + 100 & !is.na(0)

Answers:

• 110

• False

• True

• 0

39. Suppose X is the vector c(1:10). Which R code will swap the values of the 3rd element of X and the 7th element of X?

Answers:

• X[c(3,7)] <- X[c(7,3)]

• replace(X, c(3, 7), c(7,3)

• X[3] <- X[7]; X[7] <- X[3]

• X[7] <- X[3]; X[3] <- X[7]

40. What is the output of dim(matrix(1:10, ncol=2))?

Answers:

• 20

• 5 2

• 10

• 2 5

41. Which is an INCORRECT command to get an explanation on any specific named function?

Answers:

• ?rnorm

• ts?

• help(lm)

• ??log

42. What's the output for command: is.nan(NA)

Answers:

• NA

• -Inf

• TRUE

• FALSE

43. Let X be a 3x4 matrix with non-zero values. The result of: > apply(X, 2, mean), is:

Answers:

• equal to the result of: >c(mean(X[1,]), mean(X[2,]), mean(X[3,]))

• equal to the result of: >c(mean(X[,1]), mean(X[,2]), mean(X[,3]), mean(X[,4]))

• equal to the result of: >c(mean(X[1,]), mean(X[2,]), mean(X[3,]), mean(X[4,]))

• equal to the result of: >c(mean(X[,1]), mean(X[,2]), mean(X[,3]))

44. What's the output for command:  is.na(0/0)?

Answers:

• NA

• FALSE

• TRUE

• -Inf

45. Which of the following is a legal sort command?

Answers:

• sort(list(10, -3, 4))

• sort(c(10, -3,4))

• sort(data.frame(x = c(10, -3, 4)))

• sort(10, -3,4)

46. What does the following R function output? xxx <- c(1, 1, 2, 2, 3, 3, NA, NA); yyy <- c(rep(0, 4), rep(1, 4)); cor(yyy, xxx)

Answers:

• R squared

• A correlation coefficient

• An error message

• NA

47. Which R function fits a simple linear regression model of x predicting y without an intercept?

Answers:

• lm(y ~ x, intercept=F)

• regress y x, nointercept

• proc reg; model y=x; intercept=F; run;

• lm(y ~ -1 + x)

48. Which R function can be used to produce a simple scatterplot of a numeric vector Y versus a numeric vector X?

Answers:

• scatter(Y, X)

• plot(Y, X)

• plot(X, Y)

• scatter(X, Y)

49. Which R command is used to merge two data sets X and Y by the variable "ID" that includes all records from both data sets?

Answers:

• merge(X, Y, by="ID", all=T)

• merge(X, Y, id="ID", all=T)

• combine(X, Y, by="ID")

• merge(X, Y, by="ID")

50. Suppose you need to randomly assign 100 study subjects into one of 5 groups such that there are exactly 20 subjects in each group. Which of the following R functions creates a variable Y that randomly distributes the 100 study subjects into 5 groups of equal size?

Answers:

• Y <- sample(rep(c(1:5), each=20), size=100)

• ytemp <- rnorm(100, 0, 1); Y <- cut(ytemp, breaks=c(-10, -2, -1, 1, 2, 10))

• Y <- rbinom(100, 5, 0.5)

• Y <- sample(c(1, 2, 3, 4, 5), 100, replace = TRUE)

51. What's the output for command: rep(c(1:2), each = 3)

Answers:

• 3 6 9

• 1 1 1 2 2 2

• 1:2 1:2 1:2

• 1 2 1 2 1 2

52. Which is NOT the right way to quit R program?

Answers:

• exit()

• quit()

• quit("yes")

• q()

53. Given the command: Z <- array(h, dim=c(3,4,2)), Z[] with an empty subscript or Z with no subscript stands for:

Answers:

• the data vector as it was in h

• the dimension vector c(3,4,2)

• the array of all zeros

• the entire array as an array

54. What is the output of matrix(1:10, nrow=2)[2,2]?

Answers:

• 4

• 3 4

• 2

• 2 4 6 8 10

55. What is the result of the command:                              > A<-array(2:1,dim=(2:2)) > B<-array(2:3,dim=(2:2)) > A %*% B %*% A

Answers:

• [,1] [,2] [1,] 21 14

• [,1] [,2] [1,] 14 7

• [,1] [,2] [1,] 14 21

• [,1] [,2] [1,] 7 14

56. Which is NOT the parameter of command seq()?

Answers:

• length

• times

• from

• by

57. The command:                                                            > A<-array(3:2,dim=c(2,1)) > B <- t(A)                                                                       > nrow(B)                                                         will generate:

Answers:

• [,1] [1,] 3 [2,] 2

• [,1] [,2] [1,] 3 2

• [1] 1

• [1] 2

58. What's the output of the command : x = c(T, T, NA); all(x, na.rm = TRUE)

Answers:

• NA

• TRUE

• TRUE TRUE FALSE

• FALSE

59. Please fill in the blank of the following commands to extract elements X[1,3], X[2,2] and X[3,1] from a 4 by 5 array X and replace these entries in the array X by zeroes:                                                                  > x <- array(1:20, dim=c(4,5))                                                                    > i <-                  fill in the blank                                                                                           > x[i] <- 0

Answers:

• array(c(1:3,3:1), dim=c(3,2))

• array(c(3:1,1:3), dim=c(2,3))

• array(c(1:3,3:1), dim=c(2,3))

• array(c(3:1,1:3), dim=c(3,2))

60. The command:>  state <- c("tas", "sa", "qld", "nsw", "nsw", "nt", "wa", "wa") >  statef <- factor(state) > incomes <- c(60, 49, 40, 61, 64, 60, 59, 54) > tapply(incomes, statef, mean) generates:

Answers:

• nsw nsw nt qld sa tas wa wa 61.0 64.0 60.0 40.0 49.0 60.0 54.0 59.0

• tas sa qld nsw nsw nt wa wa 60.0 49.0 40.0 61.0 64.0 60.0 59.0 54.0

• nsw nt qld sa tas wa 62.5 60.0 40.0 49.0 60.0 56.5

• tas sa qld nsw nt wa 60.0 49.0 40.0 62.5 60.0 56.5

61. The command:                                                            > A<-array(3:2,dim=c(2,1)) > B <- t(A)                                                       will generate:

Answers:

• [,1] [1,] 3 [2,] 2

• [,1] [,2] [1,] 3 2

• [,1] [,2] [1,] 2 1

• [,1] [1,] 2 [2,] 1

62. What values are displayed for the x-axis limits of the following plot?  plot(c(0, 2), c(0, 1), xaxt="n", yaxt="n"); axis(side=2, labels=c("0", "10"), at=c(0,1))

Answers:

• 0, 2

• No values are displayed

• 0, 1

• 0, 10

63. What is the result of the command:                              >array(2:1,dim=(2:2))%*%array(2:3,dim=(2:2))

Answers:

• [,1] [,2] [1,] 4 3

• [,1] [1,] 8

• [,1] [,2] [1,] 6 2

• [,1] [1,] 7

64. matrix(1:4, ncol = 2)[1,]

Answers:

• 1 3

• 1 4

• 1 2

• 2 4

65. Which R function outputs the day of the month from X <- "2014-May-15"?

Answers:

• strsplit(X, "-")

• substr(X, 10, 11)

• date(X, "day")

• split(X, "-")[3]

66. What's the output for command: paste("O", "M", "G")

Answers:

• "O" "M" "G"

• "OMG"

• "O M G"

• "omg"

67. What is the result of the command:                              >array(2:1,dim=(2:2))*array(2:3,dim=(2:2))

Answers:

• [,1] [,2] [1,] 6 2

• [,1] [1,] 8

• [,1] [1,] 7

• [,1] [,2] [1,] 4 3

68. Which class avoids making copies of objects?

Answers:

• s3

• R5 (reference class)

• s4

69. What is the output of the following calculation? t(c(1, 1)) %*% c(1, 1)

Answers:

• 4

• 1

• 2

• A 2x2 matrix with all cells equal to 1

70. Let X be a n-dimension vector. Which test for:  "no value of X is NA"

Answers:

• all(!is.na(X))

• all(is.na(X))

• !all(is.na(X))

• !is.na(X)

71. What is the output of: rrr <- 5.45667; sprintf("%1.f", round(rrr, 3))

Answers:

• 5

• 5.457

• "5"

• 5.5

72. Which R function will generate an integer X from Y <- "9.145", where Y is stored as a text string?

Answers:

• X <- is.integer(Y)

• X <- as.integer(Y)

• X <- round(Y, 0)

• X <- as.numeric(Y)

73. what's the result from following code a  = 2; fun = function(x) {a <<- a + 1;return(x + 1)}; z = fun(3); a + z;

Answers:

• NA

• 5

• 7

• 6

74. If Y is a multi-modal vector of integers, which R function would return all modes of Y (the most frequent value(s) of Y)?

Answers:

• names(table(Y))[table(Y)==max(table(Y))]

• mode(Y)

• sort(table(Y), decreasing=T)

• sort(Y, decreasing=T)[1]

75. What is the result of command: labs <- paste(c("X","Y"), 1:10, sep="")?

Answers:

• the row vector ["X1" "Y1" "X2" "Y2" "X3" "Y3" "X4" "Y4" "X5" "Y5" "X6" "Y6" "X7" "Y7" "X8" "Y8"

• the row vector ["X1" "Y2" "X3" "Y4" "X5" "Y6" "X7" "Y8" "X9" "Y10"]

• the row vector ["Y1" "Y2" "Y3" "Y4" "Y5" "Y6" "Y7" "Y8" "Y9" "Y10"]

• the row vector ["X1" "X2" "X3" "X4" "X5" "X6" "X7" "X8" "X9" "X10"]

76. R operates on named data structures. The simplest such structure is the numeric vector, which is a single entity consisting of an ordered collection of numbers. To set up a vector named x, consisting of 10.4, 5.6, 3.1, 6.4 and 21.7, which is the INCORRECT command:

Answers:

• assign("x", c(10.4, 5.6, 3.1, 6.4, 21.7))

• c(10.4, 5.6, 3.1, 6.4, 21.7) -> x

• x <- c(10.4, 5.6, 3.1, 6.4, 21.7)

• (All of these are correct)

77. Given the command: Z <- array(h, dim=c(3,4,2)), Z[1:24] stands for:

Answers:

• the dimension vector c(3,4,2)

• the entire array as an array

• the array of all zeros

• the data vector as it was in h

78. What is NOT the right answser about how to get help manual for function 'plot' in a running R session.

Answers:

• ?plot

• help(plot)

• help("plot")

• ?"plot"

• help.start(plot)

79. Which of the following command only assumes a common continuous distribution?

Answers:

• wilcox.test(A, B)

• t.test(A, B, var.equal=TRUE)

• t.test(A, B)

• var.test(A, B)

80. What's right about running following command: setClass("Test", contains = "VIRTUAL"); obj <- new("Test")

Answers:

• Error produced when create an instance for class "Test"

• A S3 class "Test" is defined

• Error produced when define the class.

• A new instance of class "Test" is generated.

81. Given x <- c(1:3,NA), the command: (x+1)[(!is.na(x)) & x>0] -> z generates:

Answers:

• the row vector [2 3 4]

• the row vector [TRUE TRUE TRUE]

• the row vector [FALSE FALSE FALSE]

• the row vector [1 2 3]

82. The command > Z <- array(h, dim=c(3,4,2)) would use h to set up 3 by 4 by 2 array in Z. However if h is shorter than 24, its values___________________.

Answers:

• makes Z an array of all zeros

• are just the same as the length of h

• would signal an error about mismatching length

• are recycled from the beginning again to make it up to size 24

83. plot.lm is a function in R, what kind of programming style it is?

Answers:

• s3

• n6

• s4

• R5

84. Which R code subsets a matrix Y to only those records (rows) where a variable x (in Y) is less than 100?

Answers:

• Y[which(x<100)]

• Y[,which(x<100)]

• Y[where(x<100),]

• Y[x<=100]

85. Which one is the correct expression regarding outer product of two arrays?

Answers:

• > ab <- a %o% b

• > ab <- outer(a, b, *)

• > ab <- outer(a, b, %o%)

• > ab <- a * b

86. What R function can be used to tabulate values of categorical variable Y (columns) by categorical variable X (rows), including missing values?

Answers:

• tabulate(X, Y, na.omit=F)

• table(X, Y, useNA="always")

• table(X*Y, na.rm=F)

• table(X, Y, na.include=T)

87. The command: > fruit <- c(5, 10, 1, 20); > names(fruit) <- c("orange", "banana", "apple", "peach"); > lunch <- fruit[c("apple","orange")]; > lunch; generates:

Answers:

• apple orange 1 5

• 1 5

• apple orange

• 1 5 apple orange

88. Which of the following is NOT one of R's basic vector types?

Answers:

• integer

• double

• (All of these are valid)

• logical

• complex

89. Which of the following statements regarding mixed vector and array arithmetic is true?

Answers:

• As long as short vectors and arrays only are encountered, the arrays can have the different dim attribute or an error results

• Any vector operand shorter than a matrix or array operand generates an error

• The expression is scanned from right to left

• Any short vector operands are extended by recycling their values until they match the size of any other operands

90. To test the residuals of a regression model X for heteroscedastisity, you can use this command:

Answers:

• bgtest(X)

• heteroscedastisity(X)

• gqtest(X)

• jarqueberaTest(residual(X))

91. To test the residuals of model X for autocorrelation of first order, you can use this command:

Answers:

• bgtest(X)

• jarqueberaTest(residual(X))

• gqtest(X)

• autocorrelationtest(X)

92. Which is the INCORRECT way to get the vector [1 1 1 3 3 3 5 5 5]?

Answers:

• x<-seq(1,5,by=2); rep(x, times=3)

• x<-seq(1,5,by=2); rep(x, each=3)

• x<-c(1 1 1 3 3 3 5 5 5)

• x<-seq(1,5,by=2); s<-rep(x, times=3); sort(s)

93. What is the result of command: z <- c(1:3,NA); ind <- is.na(z); z ?

Answers:

• the row vector [FALSE FALSE FALSE TRUE]

• the row vector [TRUE TRUE TRUE FALSE]

• the row vector [1 2 3 FALSE]

• the row vector [1 2 3 NA]

94. Let h be a numeric vector shorter than 24, the command: dim(h) <- c(3,4,2)

Answers:

• would signal an error about mismatching length

• is just the same as the length of h

• makes an array of all zeros

• is recycled from the beginning again to make it up to size 24

95. Which is INCORRECT regarding the command: T=40; x=rnorm(T, 1,4)?

Answers:

• it generates 40 random numbers

• it generates 40 random numbers from normal distribution with mean of 1

• it generates random numbers from 40 different normal distributions

• it generates 40 random numbers from normal distribution with standard deviation of 4