

They can, but the matching takes place via the class table. At first, it might appear that students cannot be matched to their schools. Storing the school id in the class table is more efficient: there are five classes, and therefore only five pieces of information need to be stored. There are 100 student, and therefore 100 pieces of information would need to be stored. If the school id had been stored in the student table, each student would have the id. Note that the id representing the schools is located in the class table.

Similarly, the class table contains an id representing the school, and same id is found exactly once in the school table. The id is also found in the class table but only once. In a normalised student table, there is an id representing the class. It is more efficient to store the class and school information in separate tables. That is, many rows would contain identical class and school information. But this is an inefficient way to store the information because the rows containing students common to a class all contain the same class information similarly, the rows containing students common to a school all contain the same school information.
HOW TO SELECT COLUMNS ON MICROSOFT ACCESS ON MAC PLUS
For instance, the student table could have contained the student information plus the class information and the school information. The aim of normalisation is to reduce redundancy in the information stored in the tables. The workbook has a structure similar to that of a proper database, in that the tables are normalised. The str() function gives the structure of the student data frame. As with the sqlFetch() function, the table is imported in the form of a data frame, and the data frame is given the name student. The star (*) in the query means “all columns in the table”, and so the query imports the complete Student table. The table name ( Student$) contains a special character ($ – other special characters include spaces and brackets), and therefore within the query, it should be surrounded by back quotes (`). The query requests that the whole Student table be imported and so it does exactly the same as the sqlFetch() function in the previous example (some of the versatility of the sqlQuery() function will be demonstrated later). The query is passed to the sqlQuery() function via its name qry. Note that the query is surrounded by quotes. The query in the example below is formulated outside the sqlQuery() function, and is assigned the name qry. The sqlQuery() function requires two arguments: the connection, and a SQL query. But the method is versatile because queries can, among other things, select part of a table, they can manipulate the data before the data are imported into R, and they can request tables to be merged before the data are imported into R. The method is complex because it requires a properly formatted SQL query (more on SQL later). In most situations, any one of these methods is simpler and possibly preferable to using ODBC, but for the sake of completeness, I outline the ODBC method here.Ī more versatile but more complex method is available using the sqlQuery() function. It uses the read.xlsx() function available in the xlsx package. A third alternative allows Excel files in the XLSX format to be imported. The function depends on functionality from the scripting language perl, and therefore it requires perl ( ) to be installed. Second, Excel files can be accessed using the read.xls() function available in the gdata package. The package allows for the general manipulation of Excel files and the production of Excel reports with graphics without the need for Excel to be installed. First, Excel files can be accessed using the loadWorkbook() and readWorksheet() functions available in the XLConnect package. Alternatively, there are at least three packages that allow Excel files to be accessed directly.

Arguably the simplest is to save a spreadsheet as a comma or tab separated file, then to import the data into R using the read.table() or read.csv() functions. Spreadsheets are a common method for distributing data, and R provides several methods for accessing spreadsheet data.
