Showing posts with label import. Show all posts
Showing posts with label import. Show all posts

Sunday, December 22, 2013

2.3 Importing and making a matrix of a dataset

Importing and making a matrix of the dataset


Reviewing the previous steps

In the previous steps of this tutorial you learned how to set the working directory, how to convert to a .csv-file and how to check your dataset. By executing these steps you are ready to import the dataset into the R console.

Figure 17: Making a matrix of the imported dataset
Figure 17: Making a matrix of the imported dataset

Importing the dataset

In the example of Figure 17 the dataset Projects.csv is imported. This is executed by the code read.csv('Projects.csv').

Making a variable of the dataset

Making a importing and making a variable of the dataset could also be done by one command, in case of calling the variable of the dataset Projects use the following command: Projects<-read.csv('Projects.csv'). The dataset is now attached to the variable called Projects

Making a matrix of the dataset

To make a matrix of the dataset, use the command attach(*name of the variable*)
In the example of Figure 17 a matrix is created for the variable Projects with the code attach(Projects). To give an overview of the matrix of the dataset you can make R present a summary by using the command summary(*name of the variable*). In the example a summary is presented of the dataset Projects.csv. with the variable Projects by using the command summary(Projects).

To the next step: Modifying data in R

Saturday, December 21, 2013

1.3 Importing the data set in the R Console

Importing data in R

Verify if the correct Working Directory is set. Also make sure that the data files are placed in this folder. 
If these two operations are executed, you are ready to import data files into the R console.

Importing the csv file


Figure 6: Imorting and making a matrix of the data set in the r console
Figure 6: Importing and making a matrix of the data file


You can select the file you wat to import into the R console. This can be executed in the following way:
  1. Importing the data file: Type in the command read.csv('*name of your file*'). In the example of Figure 6 the file Flowersales.csv is imported. In this example the code read.csv('Flowersales.csv') is used. After pressing Enter information about the data set appears in the R console. Please note that the code that is inserted in the R console is case sensitive, "flowersales.csv" could not be found. Please also not that the name of the file has to be put between 'quotation marks'.
  2. Creating a variable for the data file:  The next step is creating variables for the data file. In the introduction of this tutorial it is explained how to create a variable with the <- code. For the data file Flowersales.csv a variable is created. This is done by using the following code: Flowersales<-read.csv('Flowersales.csv'). The file Flowersales.csv is no longer seen as an external file, but as a variable in this session. This makes analyzing the data set in the R console way easier. The purpose of making a variable is that the code for importing the data file [read.csv('Bloemenverkoop.csv')] does not have to be insterted every time. Now that a variable is created for this data file, you only have to type in Flowersales to show information about the data file.
  3. Making a matrix of the data file: By making a matrix of the just created variable Flowersales, the R console could read the data in a better way. Making a matrix in the R console is easy by using the command: attach(*Name of the variable of the data file*). Figure 6 shows that the command attach(Bloemenverkoop) is used (Bloemenverkoop is the Dutch word for Flowersales). Now catagories of the data set could easy be shown in the R consol. For example by showing information about the catagory Tulips, you easily use the command Tulips. In the next chapter you will see that in front of the command Tulips differerent functions could be placed to analyze this catagory.

Remarks

  • Like chapter 1.1 explains about the Working Directory; The Working Directory is a map in which R searches for data files. So, the data files you want to analyze have to be placed in this map to be found by R.
  • It is not neccesary to name the variable Flowersales, you could decide yourself how you name the variable. With the <- code R recognized the data file. Flowers<-read.csv('Flowersales.csv') is for example acceptable as well. In this case the variable Flowers has to be used during the whole analyzing process in the R console.