Information about Exercise

Class Name: Example Class

Exercise Name: Introduction to R

Student Name: Robert Engle

Student Version: 3

Number of questions: 23

Date and time of compilation: 2021-02-28 08:45:35 at msperlin-DELL


Supplement Material:

Analyzing Financial and Economic Data with R .


Notes:

Exercises

  1. The R language was developed based on what other programming language?


    1. C++
    2. Javascript
    3. Python
    4. S
    5. Julia

  2. What are the names of the two authors of R?


    1. Roger Federer and Rafael Nadal
    2. Linus Torvalds and Richard Stallman
    3. Ross Ihaka and Robert Gentleman
    4. Guido van Rossum and Bjarne Stroustrup
    5. John Chambers and Robert Engle

  3. Why is R special when comparing to other programming languages, such as Python, C++, javascript and others?


    1. It was designed for analyzing data and producing statistical output
    2. Quick code execution
    3. Works on any plataform such as Windows, Unix, MacOS
    4. Easy to use
    5. Makes it easy to write mobile apps

  4. What was the reason the programming language was named R?


    1. Letter R is shared in the first names of its authors.
    2. The mother of one of the authors is called Renata.
    3. R = Reausable code.
    4. It was the only available letter, not yet used as a programming language.
    5. Letter R is cool!

  5. Consider the following alternatives about R and RStudio:

    I - R was developed in 2018 and is an innovative and unstable project;

    II - RStudio is an modern interface to R, increasing productivity;

    III - R has compatibility with different programming languages;

    Which alternatives are correct?


    1. FALSE, TRUE, TRUE
    2. TRUE, TRUE, TRUE
    3. TRUE, TRUE, FALSE
    4. FALSE, TRUE, FALSE
    5. TRUE, FALSE, FALSE

  6. Once you have R and RStudio installed, head over to the CRAN package website1 and look for technologies you use in your work. For example, if you use Google Sheets2 ostensibly in your work, you will soon discover that there is a package in CRAN that interacts with spreadsheets in the cloud.


  7. On the CRAN site you can also install the Rtools application. What is it for?


    1. Compile R packages locally
    2. Make coffee (?).
    3. Compile technical reports.
    4. Build web pages.
    5. Compile graphics.

  8. Use Google to search for R groups in your region. Check if the meetings are frequent and, if you don’t have a major impediment, go to one of these meetings and make new friends.


  9. Go to the RBloggers website1 and look for a topic of interest to you, such as football (soccer) or investments (investments). Read at least three of the found blog posts.


  10. If you work in an institution with data infrastructure, talk to the person in charge of the IT department and verify what technologies are used. Check if, through R, it is possible to access all tables in the databases. For now there is no need to write code, yet. Just check if this possibility exists.


  11. In RStudio, create a new script and save it in a personal folder. Now, write R commands in the script that define two objects: one holding a sequence between 1 and 100 and the other with the text of your name (ex. ‘Richard’). Execute the whole script with the keyboard shortcuts.


  12. In the previously created script, use function message to display the following phrase in R’s prompt:"My name is ....".


  13. Within the same script, show the current working directory (see function getwd, as in print(getwd())). Now, change your working directory to Desktop (Desktop) and show the following message on the prompt screen: 'My desktop address is ....'. Tip: use and abuse of RStudio’s autocomplete tool to quickly find the desktop folder.


  14. Use R to download the compressed zip file with the book material, available at this link1. Save it as a file in the temporary session folder (see function tempfile).


  15. Use the unzip function to unzip the downloaded file from previous question to a directory called'afedR-files' inside the “Desktop” folder. How many files are available in the resulting folder? Tip: use the recursive = TRUE argument with list.files to also search for all available subdirectories.


  16. Every time the user installs an R package, all package files are stored locally in a specific directory of the hard disk. Using command Sys.getenv('R_LIBS_USER') and list.dirs, list all the directories in this folder. How many packages are available in this folder on your computer?


  17. In the same topic as previous exercise, list all files in all subfolders in the directory containing the files for the different packages (see command Sys.getenv('R_LIBS_USER')). On average, how many files are needed for each package?


  18. Use the install.packages function to install the BatchGetSymbols package on your computer. After installation, use function BatchGetSymbols to download price data for the IBM stock in the last 15 days. Tips: 1) use function Sys.Date() to find out the current date and Sys.Date()- 15 to calculate the date located 15 days in the past; 2) note that the output of BatchGetSymbols is a list – a special type of object – and that the price data is located in the second element of that list.


  19. The cranlogs package allows access to downloads statistics of CRAN packages. After installing cranlogs on your computer, use the cranlogs::cran_top_downloads function to check which are the 10 most installed packages by the global community in the last month. Which package comes first? Tip: Set the cran_top_downloads function input to when = 'last-month'. Also, be aware that the answer here may not be the same as you got because it depends on the day the R code was executed.


    1. tidyselect
    2. xfun
    3. rlang
    4. glue
    5. tibble

  20. Using the devtools package, install the development version of the ggplot2 package, available in the Hadley Hickman repository. Load the package using library and create a simple figure with the code qplot(y = rnorm(10), x = 1:10).


  21. Using your programming ability check on your computer which folder, from the “Documents” directory (shortcut = ~), has the largest number of files. Display the five folders with the largest number of files on R’s prompt.


  22. Imagine a survey involving analyzing your household budget over time. Data are available in electronic spreadsheets separated by month, for 10 years. The objective of the research is to understand if it is possible to purchase a real state property in the next five years. Within this setup, detail in text the elements in each stage of the study, from importing the data to the construction of the report.


  23. Based on the study proposed earlier, create a directory structure on your computer to accommodate the study. Create mock files for each subdirectory (see directory structure at section @ref(directories)). Be aware you can create mock files and direction all in R (see functions cat and dir.create).


    1. S+
    2. C++
    3. Python
    4. Matlab
    5. Javascript