Thursday, December 17, 2015

R test answers of 2016.

Find Complete and recently updated Correct Question and answers of R. All Answers updated regularly with new questions. Upwork R test answers of 2016.



Question:* Which R function fits a simple linear regression model of x predicting y?

Answer: • lm(y ~ x)

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

Answer: • 1 3 1 3

Question:* Which R function provides a histogram of the numeric vector X?

Answer: • hist(X)

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

Answer: • 1 2 1 2 1 2

Question:* Which R function imports a comma separated file "X.csv"?

Answer: • read.csv("X.csv")

Question:* What's the output for command: print("Hello World")

Answer: • Hello World

Question:* What does the following R code output? seq(2,10, by=2)

Answer: • 2 4 6 8 10

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

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

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

Answer: • sort(X, decreasing=T)

Question:* What's the value of x after command: x <- 3 < 4

Answer: • TRUE

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

Answer: • NA

Question:* In order to apply lag operator for the data, you should:

Answer: • convert the data into the time-series object

Question:* Which R function provides basic descriptive summary statistics for a numeric vector x?

Answer: • summary(x)

Question:* The entities on which R operates are technically known as:

Answer: • objects

Question:* What's the output for command is.nan(0/0)

Answer: • TRUE

Question:* How does one obtain the FIRST element of x when x = 1:9?

Answer: • x[1]

Question:* What is an appropriate syntax for a 'for' loop in R to run specific simulation code nnn times?

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

Question:* Which command is used to test if an object is a time series?

Answer: • is.ts

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

Answer: • xlim=c(0, 1)

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

Answer: • 2

Question:* 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=" ")

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

Question:* Which of the following is NOT a valid data import function?

Answer: • readdata

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

Answer: • FALSE FALSE FALSE TRUE

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

Answer: • "OMG"

Question:* 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?

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

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

Answer: • table(X, Y)

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

Answer: • 1 2 3

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

Answer: • x != y

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

Answer: • abline(0, 1)

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

Answer: • 1 4

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

Answer: • "OMG"

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

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

Question:* Which R function will generate a mean for each row in a numeric matrix X with intermittent missing values?

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

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

Answer: • NA

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

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

Question:* 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?

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

Question:* Which command is correct in order to load excel file into R?

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

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

Answer: • True

Question:* 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?

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

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

Answer: • 5 2

Question:* Which is an INCORRECT command to get an explanation on any specific named function?

Answer: • ts?

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

Answer: • FALSE

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

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

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

Answer: • TRUE

Question:* Which of the following is a legal sort command?

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

Question:* 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)

Answer: • NA

Question:* Which R function fits a simple linear regression model of x predicting y without an intercept?

Answer: • lm(y ~ -1 + x)

Question:* Which R function can be used to produce a simple scatterplot of a numeric vector Y versus a numeric vector X?

Answer: • plot(X, Y)

Question:* 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?

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

Question:* 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?

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

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

Answer: • 1 1 1 2 2 2

Question:* Which is NOT the right way to quit R program?

Answer: • exit()

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

Answer: • the entire array as an array

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

Answer: • 4

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

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

Question:* Which is NOT the parameter of command seq()?

Answer: • times

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

Answer: • [1] 1

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

Answer: • TRUE

Question:* 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

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

Question:* 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:

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

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

Answer: • [,1] [,2] [1,] 3 2

Question:* 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))

Answer: • No values are displayed

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

Answer: • [,1] [1,] 7

Question:* matrix(1:4, ncol = 2)[1,]

Answer: • 1 3

Question:* Which R function outputs the day of the month from X <- "2014-May-15"?

Answer: • substr(X, 10, 11)

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

Answer: • "O M G"

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

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

Question:* Which class avoids making copies of objects?

Answer: • R5 (reference class)

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

Answer: • 2

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

Answer: • all(!is.na(X))

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

Answer: • "5"

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

Answer: • X <- as.integer(Y)

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

Answer: • 7

Question:* 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)?

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

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

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

Question:* 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:

Answer: • (All of these are correct)

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

Answer: • the data vector as it was in h

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

Answer: • help.start(plot)

Question:* Which of the following command only assumes a common continuous distribution?

Answer: • wilcox.test(A, B)

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

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

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

Answer: • the row vector [2 3 4]

Question:* 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___________________.

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

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

Answer: • s3

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

Answer: • Y[,which(x<100)]

Question:* Which one is the correct expression regarding outer product of two arrays?

Answer: • > ab <- a %o% b

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

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

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

Answer: • apple orange 1 5

Question:* Which of the following is NOT one of R's basic vector types?

Answer: • (All of these are valid)

Question:* Which of the following statements regarding mixed vector and array arithmetic is true?

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

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

Answer: • gqtest(X)

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

Answer: • bgtest(X)

Question:* Which is the INCORRECT way to get the vector [1 1 1 3 3 3 5 5 5]?

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

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

Answer: • the row vector [1 2 3 NA]

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

Answer: • would signal an error about mismatching length

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

Answer: • it generates random numbers from 40 different normal distributions



No comments:

HTML5 Upwork (oDesk) TEST ANSWERS 2022

HTML5 Upwork (oDesk) TEST ANSWERS 2022 Question: Which of the following is the best method to detect HTML5 Canvas support in web br...

Disqus for upwork test answers