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?

Answers

·        -sales-2020

·        2020_sales

·        sales_2020

·        _2020sales

Explanation:  "sales_2020" is the name of the variable, and "500000" is the value that has been allocated to it in this case. It is usual practice to use the underscore character (_) to separate words in variable names, which makes the names easier to read. The use of snake case is another name for this behavior. When assigning, the equal symbol (=) is often used.

 

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?

Answers

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

Answers

·        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?

Answers

·        Assignment

·        Logical

·        Relational

·        Arithmetic

Explanation: The analyst makes use of the assignment operator (-) in the R code samples that are supplied here. In R, assigning values to variables is accomplished with the help of this operator.

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.

Answers

·        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?

Answers

·        Pipes

·        Comments

·        Packages

·        Vectors

Explanation: A "package" in R is a collection of reusable functions and documentation explaining how those functions may be put to use. R packages are bundled collections of code, data, and documentation that expand the functionalities of the R programming language. They make it possible to organize, exchange, and distribute code, which in turn makes it simpler for users to get access to and make use of certain functionalities for a variety of different activities.

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

Answers

·        True

·        False

Explanation: That's just right! It is true that CRAN (Comprehensive R Archive Network) is an online repository that holds R packages and resources that are associated with them. Installing R packages in RStudio often involves doing so from the Comprehensive R Archive Network (CRAN), which is a centralized repository that houses the whole of the R package ecosystem.

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?

Answers

·        Pipe

·        Nested function

·        Vector

·        Data frame

Shuffle Q/A 1


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

Answers

·        1021

·        1020

·        1102

·        2120


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

Answers

·        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?

Answers

·        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?

Answers

·        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?

Answers

Explanation: You may use the dplyr package in R to filter a data frame called persons where the age is 10, organize the data by height, and group it by gender. 

 

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

Answers

·        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?

Answers

·        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?

Answers

·        lubridate()

·        datetime()

·        now()

·        mdy()

Explanation: In this particular illustration, %B stands for the whole name of the month, %d stands for the day of the month, and %Y stands for the year as a decimal number including the century. Modify the format option so that it corresponds with the particular format used for the date strings included in the dataset.

 

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.

Answers

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

Answers

·     patient_details_1.R

·        title*123.R

·        p1+infoonpatients.R

·        patient_data.R

Shuffle Q/A 2


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

Answers

·        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?

Answers

·        The CRAN archive

·        The RStudio website

·        The tidyverse

·        Python

Explanation: CRAN, which stands for Comprehensive R Archive Network, is a well-known package archive that is committed to providing users of R with code that has been authenticated and tested. CRAN is a centralized repository that offers a broad variety of R packages. Its objective is to provide users with easy access to packages that are dependable and well-maintained for a variety of applications. A review procedure is used so that the R community can ensure that the packages available on CRAN continue to be of a high quality and reliable.

 

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)) %>%

Answers

·        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 _____.

Answers

·        an operator

·        a letter

·        an underscore

·        a number

Explanation: When you are setting up a variable in R for usage, the name of the variable you choose should start with either a letter or a period (.).

 

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?

Answers

·        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?

Answers

·        “4.10.19”

·        “4/10/2019”

·        “2019-10-4”

·        “2019-4-10”

Explanation: After this piece of code has been executed, the value of the Date object that is corresponding to April 10, 2019 will be allocated to the date_object variable. After that, you'll be able to use this object in R for further analysis or alteration of date-related activities.

 

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

Answers

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

Answers

·        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?

Answers

·        A data frame

·        A tidyverse

·        A data type

·        A package

Explanation: It is recommended that the data analyst think about developing a R package in order to provide reusable and shared code components in R. A collection of R functions, documentation, example datasets, and code tests are referred to as a R package when they are packed together. Because it enables the structuring, documenting, and distribution of code, it is much simpler to exchange and reuse code across a variety of applications.

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?

Answers

·        Base

·        CRAN

·        tidyverse

·        Recommended

Explanation: The tidyverse is a good option for a data analyst who requires a system of packages that share a similar design philosophy for the purpose of data manipulation, exploration, and visualization in R and who is in need of such a system. The tidyverse is a collection of R packages that are designed to operate in concert with one another in order to provide a method of data analysis that is unified and coherent.

Shuffle Q/A 3

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

Answers

·        alpha_21

·        alpha21

·        tidyverse

·        Recommended


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

Answers

·        v()

·        c()

·        vector()

·        combine()

Explanation: The numbers 1, 2, 3, 4, and 5 are inserted into a new numeric vector that has been given the name my_vector. To generate vectors with a wide range of possible kinds, the c() function may be used with a wide variety of value types, including numeric values, character values, and logical value types.

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

Answers

·        Recommended packages

·        Base packages

·        Community packages

·        CRAN packages

Explanation: When you begin your first programming session in RStudio, many critical foundation packages are immediately connected. These packages provide vital capabilities for fundamental data manipulation, analysis, and visualization.

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

Answers

·        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?

Answers

·        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?

Answers

·        myd()

·        mdy()

·        dmy()

·        ymd()

Explanation: In this demonstration, the Date object that corresponds to January 10, 2022 will be allotted to the converted_date variable. When it comes to dealing with dates and times in R, the powerful lubridate package has a function called mdy() that is responsible for handling a variety of formats.

35. What is the relationship between RStudio and CRAN?

Answers

·        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?

Answers

·        Pipe

·        Comment

·        Argument

·        Vector

Explanation: The data analyst may utilize R's pipe operator (%>%) to simplify nested function calls and make the code more easily understandable for the people who have a stake in the project. In most cases, the magrittr or dplyr packages are the ones that are linked with the pipe operator.

The analyst is given the flexibility to chain actions in a left-to-right sequence when they make use of the pipe operator, which improves readability and reduces the necessity for nested function calls. Workflows involving data modification and analysis benefit tremendously from its use.

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?

Answers

·        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?

Answers

·        tidyr

·        readr

·        ggplot2

·        dplyr

Explanation: The dplyr package, which is part of the tidyverse, offers a standardized collection of functions for doing frequent data manipulation tasks such as choosing and filtering data. Because of its user-friendly syntax and extensive data manipulation features, the dplyr package, which is a component of the tidyverse ecosystem, has found widespread use.

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

Answers

·        Nested function

·        Variable

·        Installed package

·        Vector

Explanation: In R programming, the pipe operator (%>%) may be used as an alternative to nested function calls. This provides a mechanism to chain actions that is both more legible and expressive. The pipe operator is often implemented within the framework of the tidyverse, where it is connected with the magrittr or dplyr packages and is used frequently.

The use of the pipe operator, as opposed to nesting functions, results in code that is more linear and simpler to comprehend. Use the pipe operator to link together a series of actions in a left-to-right fashion rather than creating nested function calls. Workflows involving data modification and analysis may benefit tremendously from this feature.

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

Answers

·        Function names should be capitalized

·        Function names should be verbs

·        Function names should be very long

·        Function names should start with a special character

Explanation: When naming functions in R, one of the best practices is to create names that are meaningful, descriptive, and that reflect the function's purpose. This helps increase the readability of the code and makes it simpler for others, including yourself, to comprehend the role that the function plays within the larger codebase.

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.

Answers

·        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?

Answers

·        Assignment

·        Arithmetic

·        Conditional

·        Logical

Explanation: The data analyst makes use of the division operator (/) in the code that reads "print(100 / 10)." R's division operator is a mathematical operator that divides the value on the left side by the value on the right side. In other words, it takes the left value and divides it by the right value.

In this particular illustration, the division process is represented as 100 divided by 10, which yields the number 10. The result of the division operation is then shown by using the print() function, which displays the output of the division operation.

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

Answers

·        Assignment

·        Arithmetic

·        Relational

·        Logical

Post a Comment

Previous Post Next Post