ST308 (R) CHAPTER 1-5 QUESTIONS & VERIFIED
ANSWERS
R and RStudio are the same software.
True or False - Answers - False
What is the name of the R function we discussed that will compactly display the internal
structure of an R object? - Answers - str
What is the purpose of the R console?
The console is where - Answers - code is submitted to be evaluated
mtcars is a built in data set in R. You can obtain the column names of a data frame
using the names() function.
True or false: gear is one of the columns. - Answers - True
There is a built-in R object called (note that R is case-sensitive):
letters
What is the class of the letters object? - Answers - character
If you want to look at the help documentation for the "hist" function, what code can you
submit to the console? - Answers - help(hist)
What class of object is returned if you run the code iris[2, ]? - Answers - data.frame
Suppose the following R code is run:
vec <- c(1, 4, 10, -5)
What syntax would you use to return the third element of vec? - Answers - vec[3]
Suppose we create a list called myList as follows:
myList <- list('first' = iris, 'second'=1:3)
What is one way to access the second element of myList and have it be returned as a
vector? - Answers - myList[2]
Write the R syntax for printing out a sequence of numbers from 1 to 21, by increments
of 4. Do not include any spaces in your submission. - Answers -
seq(from=1,to=21,by=4)
What does providing a negative sign prior to an indexing vector do when subsetting a
vector?
For example, myVec[-4]. - Answers - Returns all elements except those indicated by the
indexing vector.
ANSWERS
R and RStudio are the same software.
True or False - Answers - False
What is the name of the R function we discussed that will compactly display the internal
structure of an R object? - Answers - str
What is the purpose of the R console?
The console is where - Answers - code is submitted to be evaluated
mtcars is a built in data set in R. You can obtain the column names of a data frame
using the names() function.
True or false: gear is one of the columns. - Answers - True
There is a built-in R object called (note that R is case-sensitive):
letters
What is the class of the letters object? - Answers - character
If you want to look at the help documentation for the "hist" function, what code can you
submit to the console? - Answers - help(hist)
What class of object is returned if you run the code iris[2, ]? - Answers - data.frame
Suppose the following R code is run:
vec <- c(1, 4, 10, -5)
What syntax would you use to return the third element of vec? - Answers - vec[3]
Suppose we create a list called myList as follows:
myList <- list('first' = iris, 'second'=1:3)
What is one way to access the second element of myList and have it be returned as a
vector? - Answers - myList[2]
Write the R syntax for printing out a sequence of numbers from 1 to 21, by increments
of 4. Do not include any spaces in your submission. - Answers -
seq(from=1,to=21,by=4)
What does providing a negative sign prior to an indexing vector do when subsetting a
vector?
For example, myVec[-4]. - Answers - Returns all elements except those indicated by the
indexing vector.