Question: Using Programming Language R. How to solve this? library (RSQLite) library (DBI) You need to do that everytime you start R and wish to work


Using Programming Language R. How to solve this?
library (RSQLite) library (DBI) You need to do that everytime you start R and wish to work from these libraries (if you are developing a script and running it with the source command, you can put these lines at the top of the script). Now, let's make a database connection. I've created a database, and included it in the download materials for this lab. Make sure that you've downloaded it. The function db Connect lets you connect to the database. Here we call the database connection: 'dbcon'. dbcon = db Connect(SQLite(), dbname="labo2.sqlite") Now let's see whether we were able to connect to the database. There should be 5 tables in the database; "zip' and 'tickets' relate to the Chicago parking tickets data sets, "POP 2006', and 'POP2011' are Canadian census tables, and 'CA' contains additional geographical data. If you're connected to the database, you should be able to see list of tables in the database using dbList Tables. dbListTables (dbcon) Let's have a look at the information in each data table. We can use the db Read Table function to read data of a given data table. And using the same function and with another R function, names, we can get at the column headings of the data table. names (dbReadTable (dbcon, "CA")) Thinking back to the first lab, we can print the first few rows of this database by replacing names with another function: head (dbReadTable (dbcon, "zip")) Question la, (3 points): What are the column names of the data table zip' in the lab02.sqlite database? names (dbReadTable (dbcon, "zip")) Question lb, (3 points): What are the last 5 records in the data table 'CA'? You can use the commands 'head' and 'tail' to print the first or last resp. records of a data table. Question 1c, (3 points): What are the last 3 records of the data table POP 2011'? Question ld, (3 points): How many records are in the data table 'POP 2006'? library (RSQLite) library (DBI) You need to do that everytime you start R and wish to work from these libraries (if you are developing a script and running it with the source command, you can put these lines at the top of the script). Now, let's make a database connection. I've created a database, and included it in the download materials for this lab. Make sure that you've downloaded it. The function db Connect lets you connect to the database. Here we call the database connection: 'dbcon'. dbcon = db Connect(SQLite(), dbname="labo2.sqlite") Now let's see whether we were able to connect to the database. There should be 5 tables in the database; "zip' and 'tickets' relate to the Chicago parking tickets data sets, "POP 2006', and 'POP2011' are Canadian census tables, and 'CA' contains additional geographical data. If you're connected to the database, you should be able to see list of tables in the database using dbList Tables. dbListTables (dbcon) Let's have a look at the information in each data table. We can use the db Read Table function to read data of a given data table. And using the same function and with another R function, names, we can get at the column headings of the data table. names (dbReadTable (dbcon, "CA")) Thinking back to the first lab, we can print the first few rows of this database by replacing names with another function: head (dbReadTable (dbcon, "zip")) Question la, (3 points): What are the column names of the data table zip' in the lab02.sqlite database? names (dbReadTable (dbcon, "zip")) Question lb, (3 points): What are the last 5 records in the data table 'CA'? You can use the commands 'head' and 'tail' to print the first or last resp. records of a data table. Question 1c, (3 points): What are the last 3 records of the data table POP 2011'? Question ld, (3 points): How many records are in the data table 'POP 2006
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
