Exercises

In this exercise we will learn to use packages and write data to/from external sources


  1. Install the package called RSQLite using the console and skim the console-output.

  1. Load the package dplyr and read the output in the console. What do you think it means?

  1. Open the vignette for the package DBI. If you do not have it installed, do so. This might come in handy later

  1. Together with 3-4 colleagues make a data frame with three columns. One column should be a character column with your names. The second column should be a numeric column with your shoe size. The third column should be a logical column with TRUE if you have used R before and FALSE if you have not. Assign the data frame to a name you choose yourselves

  1. Write your data frame to an excel-file (.xlsx).

  1. Open your file in Excel and edit a value. Save it and load it back into R. Does it look like you expected?

  1. Open a connection to a SQLite database on the shared drive and give it a unique name. Warning: Be sure not to overwrite each others databases. Give it a name that makes it clear it is yours.

  1. Write the data set to your database using the functions from the lecture. Check that there is actually create a table in the database.

  1. Read the data set from the database back into R and inspect it. Does it look like you expected?

  1. Disconnect from your database

  1. Ask another group for the path to their database and open a connection to it. Use this connection to show the name of their table. If this is not possible, download this SQLite database from the website, which is supposedly the result of a fictitious Group 9…

  1. Append your own data set to the other groups table. Appending is when you add your data the existing data. Read the help-file for dbWriteTable to see how it is done. Close the connection when you are done.

  1. Reopen the connection to your own database and read your table. Can you see that another group have added their data? Alternatively, reopen the database, where you added your own data, and verify, that it has indeed been added.

  1. If you have more time, try making an SQL-query to select only the data where shoe size is greater than 40. After doing this, remember to close the connection.

End of practical