MGSC 291 Exam 1 Questions and
Answers Graded A+
addition - Correct answer-R code: +
subtraction - Correct answer-R code: -
multiplication - Correct answer-R code: *
division - Correct answer-R code: /
exponent - Correct answer-R code: ^
note (anything after this symbol will be ignored by R) - Correct answer-R code: #
defines an object - Correct answer-R code: <-
combine function (creates a vector of numbers. numbers can either be separated by
commas, or by a colon (1,2,3,4) or 1:4) - Correct answer-R code: c
sequence function (creates a vector with the sequence (from, to, by) ex:
seq(1,10,0.1) creates a vector from one to 10 counting by 0.1) - Correct answer-R
code: seq()
©COPYRIGHT 2025, ALL RIGHTS RESERVED 1
,help function (opens a web browser to display a help file) - Correct answer-R code:
help(functionName)
missing value - Correct answer-R code: NA
average - Correct answer-R code: mean ()
removes all missing values (from the given data set. in R all missing values are
labeled as NA) - Correct answer-R code: na.rm=T
square root - Correct answer-R code: sqrt()
natural logarithm - Correct answer-R code: log()
e^a - Correct answer-R code: exp(a)
sample standard deviation - Correct answer-R code: sd()
sample variance - Correct answer-R code: var()
length of vector (including NAs) - Correct answer-R code: length()
dimension of data frame - rows, columns - Correct answer-R code: dim()
makes R recognize x as categorical - Correct answer-R code: factor(x)
bind (combine) objects by columns - Correct answer-R code: cbind()
bind objects by rows - Correct answer-R code: rbind()
©COPYRIGHT 2025, ALL RIGHTS RESERVED 2
, sort from smallest to largest - Correct answer-R code: sort()
sort a data frame based on specified columns(s) - Correct answer-R code: order()
round x to a decimal places - Correct answer-R code: round(x,a)
repeat x n times - Correct answer-R code: rep(x,n)
returns the position number where argument is true - Correct answer-R code:
which()
if condition is met, return a, otherwise return b - Correct answer-R code:
ifelse(cond,a,b)
sample from a dataset - Correct answer-R code: sample()
concatenate text - Correct answer-R code: paste()
returns a list of all stored objects - Correct answer-R code: object() or ls()
equal to - Correct answer-R code: ==
not equal to - Correct answer-R code: !=
less than - Correct answer-R code: <
less than or equal to - Correct answer-R code: <=
greater than - Correct answer-R code: >
©COPYRIGHT 2025, ALL RIGHTS RESERVED 3
Answers Graded A+
addition - Correct answer-R code: +
subtraction - Correct answer-R code: -
multiplication - Correct answer-R code: *
division - Correct answer-R code: /
exponent - Correct answer-R code: ^
note (anything after this symbol will be ignored by R) - Correct answer-R code: #
defines an object - Correct answer-R code: <-
combine function (creates a vector of numbers. numbers can either be separated by
commas, or by a colon (1,2,3,4) or 1:4) - Correct answer-R code: c
sequence function (creates a vector with the sequence (from, to, by) ex:
seq(1,10,0.1) creates a vector from one to 10 counting by 0.1) - Correct answer-R
code: seq()
©COPYRIGHT 2025, ALL RIGHTS RESERVED 1
,help function (opens a web browser to display a help file) - Correct answer-R code:
help(functionName)
missing value - Correct answer-R code: NA
average - Correct answer-R code: mean ()
removes all missing values (from the given data set. in R all missing values are
labeled as NA) - Correct answer-R code: na.rm=T
square root - Correct answer-R code: sqrt()
natural logarithm - Correct answer-R code: log()
e^a - Correct answer-R code: exp(a)
sample standard deviation - Correct answer-R code: sd()
sample variance - Correct answer-R code: var()
length of vector (including NAs) - Correct answer-R code: length()
dimension of data frame - rows, columns - Correct answer-R code: dim()
makes R recognize x as categorical - Correct answer-R code: factor(x)
bind (combine) objects by columns - Correct answer-R code: cbind()
bind objects by rows - Correct answer-R code: rbind()
©COPYRIGHT 2025, ALL RIGHTS RESERVED 2
, sort from smallest to largest - Correct answer-R code: sort()
sort a data frame based on specified columns(s) - Correct answer-R code: order()
round x to a decimal places - Correct answer-R code: round(x,a)
repeat x n times - Correct answer-R code: rep(x,n)
returns the position number where argument is true - Correct answer-R code:
which()
if condition is met, return a, otherwise return b - Correct answer-R code:
ifelse(cond,a,b)
sample from a dataset - Correct answer-R code: sample()
concatenate text - Correct answer-R code: paste()
returns a list of all stored objects - Correct answer-R code: object() or ls()
equal to - Correct answer-R code: ==
not equal to - Correct answer-R code: !=
less than - Correct answer-R code: <
less than or equal to - Correct answer-R code: <=
greater than - Correct answer-R code: >
©COPYRIGHT 2025, ALL RIGHTS RESERVED 3