introduction to r programming for data science coursera answers week 2
Practice Quiz
1. What is the difference between the expression c(1, 2, 3, 4, 5) and the expression c(5:1)?
- One produces a factor and the other produces a vector.
- They both produce a vector with five numbers but the first is in ascending order and the second is in descending order.
- The two expressions produce the same result.
- They both produce a factor with five numbers but the first is in ascending order and the second is in descending order.
2. Assume that the variable test_result contains the vector c(25, 35, 40, 50, 75). What is the result of the expression test_result[test_result < 50]?
- [1] 25 35 40
- [1] 25 35 40 50
- [1] TRUE TRUE TRUE FALSE FALSE
- [1] TRUE TRUE TRUE TRUE FALSE
3. What is the main difference between a list and a vector?
- A list is a multi-dimensional array of values, while a vector is a single dimensional array of values.
- It is not possible to add or remove items from a list, but you can do this with a vector.
- A list can contain nominal or ordinal values, while a vector cannot.
- A list can contain different types of data, while a vector may only contain one type of data.
4. What are three types of data you can store in an array or matrix? Select three answers.
- Integers
- Numeric valus
- Strings
- Vectors
5. In a data frame, each column is represented by a _________________ of values of the same data type.
- Vector
- Variable
- List
- Matrix
Graded Quiz
6. What is a nominal factor?
- A factor with any type or number of elements.
- A factor with ordering.
- A factor with no implied order.
- A factor that contains numeric data.
7. Assume that the variable test_result contains the vector c(25, 35, 40, 50, 75).What is the result of the expression mean(test_result)?
- 50
- 45
- 40
- 35
8. Assume you have variable called employee that contains the expression list(name = “Juan”, age = 30). What is the correct command to change the contents of the age item to 35?
- employee[“age”] <- 35
- employee[age] <- 35
- employee[age] = 35
- employee[“age”] == 35
9. What is the main difference between a matrix and an array?
- A matrix can be arranged by rows or columns, but an array is always arranged by columns.
- A matrix can contain vectors, but an array can only contain strings, characters, or integers.
- A matrix must be two dimensional, but an array can be single, two dimensional, or more than two dimensional.
- A matrix can contain multiple types of data, but an array can only contain data of the same type.
10. Assume that you have a data frame called employee that contains three variables: name, age, and title. If you want to return all the values in the title variable, what command should you use?
- employee[title]
- employee[[3]]
- employee$title
- employee.title