Why do analysts use comments in R programming

Course 7 – Data Analysis with R Programming Quiz Answers

Week 2: Programming Using Rstudio

GOOGLE DATA ANALYTICS PROFESSIONAL CERTIFICATE

Coursera RStudio Answers Study Guide

Programming Using Rstudio introduction

In this part of the course, you will gain a deeper understanding of Programming Using R in RStudio. You’ll explore the main functions and variables associated with Programming Using R and learn how to use them effectively. In addition, you’ll become familiar with R packages and how to use them within the context of Programming Using R.

This knowledge is essential for earning Coursera’s Google Data Analytics Professional Certification as well as other industry certifications related to Programming Using R. After completing this part of the course, you should be comfortable using Programming Using R to complete your analysis efficiently and accurately.

Learning Objectives

  • Describe the contents and components of the tidyverse package for R
  • Describe the concept of packages in R programming language
  • Describe the use of operators to complete calculations in the R programming language
  • Describe the fundamental concepts associated with programming in R including functions, variables, data types, pipes, and vectors
  • Install and load the tidyverse package
  • Use the browseVignettes(“packagename”) function to read through vignettes of a loaded package
  • Locate resources for help using R

Test your knowledge on programming concepts

1. Why do analysts use comments In R programming? Select all that apply.

  • To explain their code (Correct)
  • To provide names for variables
  • To act as functions
  • To make an R Script more readable (Correct)

Correct: In R programming, comments are used to explain your code and to make an R Script more readable.

2. What should you use to assign a value to a variable in R?

  • A vector
  • An argument
  • An operator (Correct)
  • A comment

Correct: You should use an operator to assign a value to a variable in R. You should use operators such as <- after a variable to assign a value to it.

3. Which of the following examples is the proper syntax for calling a function in R?

  • #first
  • data_1
  • <- 20
  • print() (Correct)

Correct: An example of the syntax for a function in R is print(). If you add an argument in the parentheses for the print() function, the argument will appear in the console pane of RStudio.

4. Which of the following examples can you use in R for date/time data? Select all that apply.

  • seven-24-2018
  • 2019-04-16 (Correct)
  • 06:11:13 UTC (Correct)
  • 2018-12-21 16:35:28 UTC (Correct)

Correct: The examples of types of date/time data that you can use in R are 06:11:13 UTC, 2019-04-16, and 2018-12-21 16:35:28 UTC. R recognizes the syntax of each of these formats as a date/time data type.

Test your knowledge on coding in R

1. An analyst includes the following calculation in their R programming:

midyear_sales <- (quarter_1_sales + quarter_2_sales) – overhead_costs

Which variable will the total from this calculation be assigned to?

  • midyear_sales (Correct)
  • quarter_1_sales
  • quarter_2_sales
  • overhead_costs

Correct: The total from this calculation will be assigned to the variable midyear_sales. The assignment operator <- follows the variable mid_sales, so the value of the calculated total is assigned to this variable.

2. An analyst is checking the value of the variable x using a logical operator, so they run the following code:

 x > 35 & x < 65

Which values of x would return TRUE when the analyst runs the code? Select all that apply.

  • 35
  • 50 (Correct)
  • 60 (Correct)
  • 70

Correct: The values 50 and 60 will return TRUE when the analyst runs the code x > 35 & x < 65. In this code, the logical operator & tells the server to return TRUE when the value of the variable is greater than 35 and less than 65.

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

sales_1 <- 100 * sales_2

Which of the following types of operators does the analyst use in the code? Select all the apply.

  • relational
  • assignment
  • arithmetic (Correct)
  • logical (Correct)

Correct: The analyst uses assignment and arithmetic operators in the code. The assignment operator (<-) assigns the variable sales_1 to the value of 100 * sales_2. The multiplication operator (*) multiplies 100 by sales_2.

test your knowledge on R packages

1. When using RStudio, what does the installed.packages() function do?

  • Creates code for analysts to use to edit their packages
  • Installs all available packages for use in an RStudio session
  • Selects the best packages to use based on an analyst’s current needs
  • Presents a list of packages currently installed in an RStudio session (Correct)

Correct: The installed.packages() function shows a list of packages currently installed in an RStudio session. You can then locate the names of the packages and what’s needed to use functions from the package.

2. In data analytics, what is CRAN?

  • A commonly used online archive with R packages and other R resources (Correct)
  • An R interface that has many of the same functions as RStudio
  • A function for finding packages to use for analysis in RStudio
  • A collection of packages that function together to make analysis in R more efficient

Correct: CRAN is a commonly used online archive with R packages and other R resources. CRAN makes sure that the R resources it shares follow the required quality standards and are authentic and valid.

3. What are ggplot2, tidyr, dplyr, and forcats all a part of?

  • A list of functions that clean data efficiently
  • A collection of core tidyverse packages (Correct)
  • A list of variables for use in programming in RStudio
  • A collection of commonly used, CRAN-based data sets

Correct: The packages ggplot2, tidyr, dplyr, and forcats are part of a collection of eight core tidyverse packages. The other core packages are: tibble, readr, purrr, and stringr.

Test your knowledge on the tidyverse

1. When working in R, for which part of the data analysis process do analysts use the tidyr package?

  • Data cleaning (Correct)
  • Data security
  • Data calculations
  • Data visualization

Correct: Analysts use the tidyr package for data cleaning. It works with wide and long data to make sure every part of a data table or data frame is the right data type and in the right place.

2. Which tidyverse package contains a set of functions, such as select(), that help with data manipulation?

  • ggplot2
  • dplyr (Correct)
  • readr
  • forcats

Correct: The dplyr package is the tidyverse package which contains a set of functions, such as select(), that help with data manipulation. For example, select() selects only relevant variables based on their names.

3. An analyst is organizing a dataset in RStudio using the following code:

arrange(filter(Storage_1, inventory >= 40), count)

Which of the following examples is a nested function in the code?

  • inventory
  • filter (Correct)
  • count
  • arrange

Correct: In the analyst’s code, filter is the nested function. It is embedded in the argument of the broader arrange function.

GOOGLE DATA ANALYTICS COURSERA ANSWERS AND STUDY GUIDE

Liking our content? Then don’t forget to add us to your bookmarks so you can find us easily!

Weekly Breakdown | Google Study Guides | Back to Top

Data Analysis with R Programming Weekly Challenge 2

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

  • utility2 (Correct)
  • 3_sales
  • _red_1
  • autos_5 (Correct)

Correct: Examples of variable names that can be used in R are autos_5 and utility2. Variable names should start with a letter and can also contain numbers and underscores.

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?

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

Correct: The code chunk c(12, 23, 51) allows you to create a vector with the values 12, 23, 51. A vector is a group of data elements of the same type stored in a sequence in R. You can create a vector by putting the values you want inside the parentheses of the combine function.

3. 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?

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

Correct: To convert the strings to date/time data types, the analyst should use the function mdy(). The mdy() function and other variations of the ymd() function convert string dates and times into date/time data types that are compatible with R.

4. 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.

  • Logical
  • Relational
  • Arithmetic (Correct)
  • Assignment (Correct)

Correct: In the code sales_1 <- (3500.00 * 12), the analyst uses an assignment (<-) and an arithmetic (*) operator. The assignment operator assigns the calculated value in parentheses to the variable sales_1 and the arithmetic operator multiplies the values in parentheses to complete the calculation.

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

  • patient_details_1.R (Correct)
  • patient_data.R (Correct)
  • p1+infoonpatients.R
  • title*123.R

Correct: The files with names that follow widely accepted naming convention rules are patient_data.R and patient_details_1.R. These file names end in .R and use only lowercase letters, numbers, and underscores. They are also clear, concise, and meaningful.

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

  • Vectors
  • Packages (Correct)
  • Pipes
  • Comments

Correct: In R, packages include reusable R functions and documentation about how to use the functions. They also include sample data sets and tests for checking your code.

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

  • True (Correct)
  • False

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

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 (Correct)
  • Vector
  • Nested function
  • Data frame

Correct: The code chunk is an example of a pipe. A pipe is a tool for expressing a sequence of multiple operations in R (in this case filtering and grouping). The operator for a pipe is %>%.

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

  • a letter (CORRECT)
  • a number
  • an operator
  • an underscore

10. Which of the following statements about vectors in R are correct? Select all that apply.

  • Data elements are defined using curly braces.
  • All data must be stored in vectors.
  • All data elements must have the same data type. (CORRECT)
  • Data elements are stored in a sequence. (CORRECT)

11. 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.

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

12. 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 (CORRECT)
  • Recommended

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?

  • filter( arrange( group_by( people, gender ), height ) , age == 10 )
  • people %>%
  •  filter(age == 10) +
  •  arrange(height) +
  •  group_by(gender)
  • group_by( arrange( filter( people, age == 10 ), height ), gender )(CORRECT)
  • people %>%
  •  group_by(gender) %>%
  •  arrange(height) %>%
  •  filter(age == 10)

14. 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 tidyverse
  • A data frame
  • A data type
  • A package (CORRECT)

15. 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?

  • Data frame
  • Vector
  • Nested function
  • Pipe (CORRECT)

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

  • _21alpha
  • 21_alpha
  • alpha_21 (CORRECT)
  • alpha21 (CORRECT)

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

  • person_1
  • 1person
  • person1 (CORRECT)
  • person(1) (CORRECT)

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

  • “2019-4-10” (CORRECT)
  • “4.10.19”
  • “2019-10-4”
  • “4/10/2019”

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

  • Assignment
  • Conditional
  • Arithmetic (CORRECT)
  • Logical

20. 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
  • dplyr (CORRECT)
  • readr
  • ggplot2

21. 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?

  • Argument
  • Vector
  • Comment
  • Pipe (CORRECT)

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

  • -sales-2020
  • 2020_sales
  • sales_2020 (CORRECT)
  • _2020sales

23.  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()
  • dmy()
  • mdy() (CORRECT)
  • ymd()

Programming Using Rstudio INTRODUCTION

With R, you’ll be able to complete your analysis more efficiently and effectively. After taking this part of the course, you will have explored the fundamental concepts associated with R. You will understand functions and variables for calculations and other programming.

In addition, you should discover R packages, collections of R functions that are often used together. With all these tools at your disposal, consider joining the learning experience in Coursera today!