Week 2: Programming using RStudio

1. A data analyst is assigning a variable to a value in their company’s sales dataset for 2020. Which variable name uses the correct syntax?

  • -sales-2020
  • 2020_sales
  • sales_2020
  • _2020sales

 

2. You want to create a vector with the values 12, 23, 51, in that exact order. After specifying the variable, what R code chunk allows you to create the vector?

  • c(12, 23, 51)
  • v(12, 23, 51)
  • c(51, 23, 12)
  • v(51, 23, 12)

3. An analyst runs code to convert string data into a date/time data type that results in the following: “2020-07-10”. Which of the following are examples of code that would lead to this return? Select all that apply.

  • mdy(“July 10th, 2020”)
  • ymd(20200710)
  • myd(2020, July 10)
  • dmy(“7-10-2020”)

4. A data analyst inputs the following code in RStudio:

change_1 <- 70

Which of the following types of operators does the analyst use in the code?

  • Assignment
  • Logical
  • Relational
  • Arithmetic

 

5. A data analyst is deciding on naming conventions for an analysis that they are beginning in R. Which of the following rules are widely accepted stylistic conventions that the analyst should use when naming variables? Select all that apply.

  • Use single letters, such as “x” to name all variables
  • Use an underscore to separate words within a variable name
  • Begin all variable names with an underscore
  • Use all lowercase letters in variable names

6. In R, what includes reusable functions and documentation about how to use the functions?

  • Pipes
  • Comments
  • Packages
  • Vectors

7. Packages installed in RStudio are called from CRAN. CRAN is an online archive with R packages and other R-related resources.

  • True
  • False

8. A data analyst is reviewing some code and finds the following code chunk:

mtcars %>%
filter(carb > 1) %>%
group_by(cyl) %>%

What is this code chunk an example of?

  • Pipe
  • Nested function
  • Vector
  • Data frame

9. A data analyst finds the code mdy(10211020) in an R script. What is the year of the date that is created?

  • 1021
  • 1020
  • 1102
  • 2120

10. Which of the following is a best practice when naming R script files?

  • R script file names should end in “.R”
  • R script file names should end in “.S”
  • R script file names should end in “.rscript”
  • R script file names should end in “.r-script”

11. How are base packages different from recommended packages in the R package ecosystem?

  • Recommended packages are made by the community and base packages are not.
  • Base packages take longer to load than recommended packages.
  • Base packages are installed and loaded by default and recommended packages are not.
  • Recommended packages are more professionally designed than base packages.

12. Why would a data analyst want to use the CRAN network when working with RStudio?

  • To add new operators to R
  • To install R packages
  • To add pipes to R
  • To install drivers to RStudio

13. A data analyst wants to take a data frame named people and filter the data where age is 10, arranged by height, and grouped by gender. Which code snippet would perform those operations in the specified order?

  •  

14. Which of the following are examples of variable names that can be used in R? Select all that apply.

  • autos_5
  • utility2
  • 3_sales
  • _red_1

     
     

15. You want to create a vector with the values 43, 56, 12 in that exact order. After specifying the variable, what R code chunk lets you create the vector?

  • c(43, 56, 12)
  • v(12, 56, 43)
  • v(43, 56, 12)
  • c(12, 56, 43)

16. An analyst comes across dates listed as strings in a dataset. For example, December 10th, 2020. To convert the strings to a date/time data type, which function should the analyst use?

  • lubridate()
  • datetime()
  • now()
  • mdy()

17. A data analyst inputs the following code in RStudio: sales_1 <- (3500.00 * 12) Which of the following types of operators does the analyst use in the code? Select all that apply.

  • Relational
  • Logical
  • Arithmetic
  • Assignment

18. Which of the following files in R have names that follow widely accepted naming convention rules? Select all that apply.

  • patient_details_1.R
  • title*123.R
  • p1+infoonpatients.R
  • patient_data.R

19. Which of the following are included in R packages? Select all that apply.

  • Naming conventions for R variable names
  • Reusable R functions
  • Tests for checking your code
  • Sample datasets

20. What is the name of the popular package archive dedicated to supporting R users authentic, validated code?

  • The CRAN archive
  • The RStudio website
  • The tidyverse
  • Python

21. A data analyst writes the following code in a script and gets an error. What is wrong with their code?

penguins %>%

filter(flipper_length_mm == 200) %>%

group_by(species) %>%

summarize(mean = mean(body_mass_g)) %>%

  • They are using too many functions.
  • The last line should not have a pipe operator.
  • The first line should have a pipe operator before penguins.
  • They are using the wrong characters for the pipe operator.

22. Fill in the blank: When creating a variable for use in R, your variable name should begin with _____.

  • an operator
  • a letter
  • an underscore
  • a number

23. You want to create a vector with the values 21, 12, 39, in that exact order. After specifying the variable, what R code chunk lets you create the vector?

  • c(39, 12, 21)
  • v(39, 12, 21)
  • v(21, 12, 39)
  • c(21, 12, 39)

24. If you use the mdy() function in R to convert the string “April 10, 2019”, what will return when you run your code?

  • “4.10.19”
  • “4/10/2019”
  • “2019-10-4”
  • “2019-4-10”

25. A data analyst wants to combine values using mathematical operations. What type of operator would they use to do this?

  • Arithmetic
  • Conditional
  • Logical
  • Assignment

26. Which of the following files in R have names that follow widely accepted naming convention rules? Select all that apply.

  • p1+infoonpatients.R
  • patient_data.R
  • patient_details_1.R
  • title*123.R

27. A data analyst wants to create functions, documentation, sample data sets, and code test that they can share and reuse in other projects. What should they create to help them accomplish this?

  • A data frame
  • A tidyverse
  • A data type
  • A package

28. A data analyst needs a system of packages that use a common design philosophy for data manipulation, exploration, and visualization. What set of packages fulfills their need?

  • Base
  • CRAN
  • tidyverse
  • Recommended

29. Which of the following are examples of variable names that can be used in R? Select all that apply.

  • alpha_21
  • alpha21
  • tidyverse
  • Recommended

30. What function is used to create vectors in the R programming language?

  • v()
  • c()
  • vector()
  • combine()

31. What type of packages are automatically installed and loaded to use in R studio when you start your first programming session?

  • Recommended packages
  • Base packages
  • Community packages
  • CRAN packages

32. Why would you want to use pipes instead of nested functions in R? Select all that apply.

  • Pipes make it easier to add or remove functions.
  • Pipes make it easier to read long sequences of functions.
  • Nested functions are no longer supported by R.
  • Pipes allow you to combine more functions in a single sequence.

33. Which of the following are examples of variable names that can be used in R?

  • value(2)
  • value-2
  • value_2
  • value%2

34. A data analyst has a dataset that contains date strings like "January 10th, 2022." What lubridate function can they use to convert these strings to dates?

  • myd()
  • mdy()
  • dmy()
  • ymd()

35. What is the relationship between RStudio and CRAN?

  • RStudio and CRAN are both environments where data analysts can program using R code.
  • CRAN creates visualizations based on an analyst’s programming in RStudio.
  • CRAN contains all of the data that RStudio users need for analysis.
  • RStudio installs packages from CRAN that are not in Base R.

36. A data analyst previously created a series of nested functions that carry out multiple operations on some data in R. The analyst wants to complete the same operations but make the code easier to understand for their stakeholders. Which of the following can the analyst use to accomplish this?

  • Pipe
  • Comment
  • Argument
  • Vector

37. A data analyst wants to assign the value 50 to the variable daily_dosage. Which of the following types of operators will they need to use in the code?

  • Relational
  • Arithmetic
  • Assignment
  • Assignment

38. A data analyst needs to find a package that offers a consistent set of functions that help them complete common data manipulation tasks like selecting and filtering. What tidyverse package provides this functionality?

  • tidyr
  • readr
  • ggplot2
  • dplyr

39. When programming in R, what is a pipe used as an alternative for?

  • Nested function
  • Variable
  • Installed package
  • Vector

40. Which of the following is a best practice when naming functions in R?

  • Function names should be capitalized
  • Function names should be verbs
  • Function names should be very long
  • Function names should start with a special character

41. A data analyst wants to create the date February 27th, 2027 using the lubridate functions. Which of the following are examples of code that would create this value? Select all that apply.

  • dmy(02272027)
  • mdy(“2027-02-27”)
  • mdy(02272027)
  • ymd(“2027-02-27”)

42. A data analyst inputs the following code in RStudio: print(100 / 10) What type operators does the analyst use in the code?

  • Assignment
  • Arithmetic
  • Conditional
  • Logical

43. A data analyst wants to store a vector in a variable. What type of operator would they use to do this?

  • Assignment
  • Arithmetic
  • Relational
  • Logical

Leave a Reply