0% found this document useful (0 votes)
5K views2 pages

R Basics Assessment

This document contains questions and answers about various R concepts including data types, functions, operators, control structures, and more. It tests knowledge on topics like creating and manipulating vectors and matrices, coercing between data types, using control flows, and common functions like c(), seq(), and nrow(). The correct answers demonstrate an understanding of basic R programming concepts.

Uploaded by

murugan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5K views2 pages

R Basics Assessment

This document contains questions and answers about various R concepts including data types, functions, operators, control structures, and more. It tests knowledge on topics like creating and manipulating vectors and matrices, coercing between data types, using control flows, and common functions like c(), seq(), and nrow(). The correct answers demonstrate an understanding of basic R programming concepts.

Uploaded by

murugan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

What is the class of the object defined by the expression x<- c(4,"a",TRUE) in R?

Ans - Character --Correct

What would be the result of following code? x <- c("x", "y", "z") as.logical(x) -
a)x y z b)NA NA NA c)"x" "y" "z" d)NaN NaN NaN
Ans: d)NaN NaN NaN --Correct

What would be the result of following code? x <- 4 class(x)


a)double b) real c)numeric d) integer
Ans: a)double - Correct

If I have two vectors, x<-c(1,3,5) and y<-c(3,2,10), what does rbind(x,y) give?
a)A 3 x 2 matrix
b)A vector length of 2
c)A 2 x 3 matrix -- Correct
d)A vector length of 3
A 3 x 3 matrix
Ans: c)A 2 x 3 matrix --Correct

Which function can be used to create collection of vectors objects?


a)c() b)concat() c)cp() d)None of the options

m
er as
Ans - a) c() --Correct

co
In R, the subsequent data types are all atomic data types except _____________.

eH w
Ans : Data Frame --Correct

o.
Which of the following statements is correct?
rs e
a)Use explicit TRUE and FALSE values when indicating logical values.
ou urc
b)R operates on named data structures.
c)All the options
d)rm command is used to remove objects in R.
Ans: c)All the options -- Correct
o
aC s

What command will you enter in the R console to get help on how to quit R?
vi y re

Ans: help(q) -- Correct

What would be the result of following code? x <- 0:4 as.logical(x)


Ans: NA NA NA NA NA -- Correct
ed d

An important property of vectors in R is that __________________.


ar stu

Ans: Elements can be of different classes --Correct

Which of the following while loops will print numbers from 1 to 4?


Ans : x<-1 while(x < 5) { print(x); x <- x+1;} --Correct
is

Which R command creates a 2 by 2 matrix with the values 1, 2, 3, and 4?


Th

Ans: m <- matrix(1:4, 2, 2) -- Correct

Which command allows you to get the median tree Height of the R sample dataset
"trees"?
Ans: median(trees$Height)
sh

What is the output of the R code? m <- c(1, 2, 3) n <- c(6, 5, 4) (m < 2) & (n >
5)
Ans: An error is thrown because the wrong operator is used. --Correct

Assume that you have a vector x <- c(3,5,1,10,12,6) and you wish to set all
elements of
this vector that are smaller than 6 to be equal to 0, what R code accomplishes

This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 07:16:05 GMT -05:00

https://www.coursehero.com/file/59704189/R-Basics-Assessmenttxt/
this?
Ans: x[x<6]<-0--Correct

Which of the following statements is correct?


a)The value Nan represents undefined value.
b)NaN can also be thought of as a missing value.
c)All the options
d)Number Inf represents infinity in R.
Ans: c)All the options --Correct

Which function is used to generate Sequences in R?


Ans: seq() --Correct

What would be the output of the subsequent code? x <- c("a", "b", "c", "c", "d",
"a") x[c(1, 3, 4)]
Ans: "a" "c" "c" --Correct

Which of the following statements is correct?


a)Infinite loops should generally be avoided.
b)The only way to exit a repeat loop is to call break.
c)Control structures like if, while, and for are used to control the flow of an R

m
er as
program.
d)All the options

co
Ans: d)All the options -- Correct

eH w
What is the function in R to get the # of observations in a data frame?

o.
Ans: nrow() --Correct
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 07:16:05 GMT -05:00

https://www.coursehero.com/file/59704189/R-Basics-Assessmenttxt/
Powered by TCPDF (www.tcpdf.org)

You might also like