9.1 Importing Dataset Tab

First, as with many things in R, there are many ways of bringing data into your workspace.

A flexible way to import data is to click on the Environment tab in the upper right window of RStudio and then click the Import Dataset tab. Multiple file type options are shown, such as text, Excel, SPSS, SAS, and Stata.

There are two options for the text option that rely on different R functions to bring the data into the workspace. Both of these options work very similarly. For either option, you can browse to where your file is located on your computer and open it.

The key items that you will need pay attention to are the column separators, i.e. how the software knows where to split columns and whether the data include column headings.

Data with an *.csv extension refers to comma separated values. You could open a file in a program like Notepad and be able to read the data. The columns are separated with commas. For these *.csv files, you choose comma for the deliminator. This concept is the same as in Excel for the function Text to Columns under the Data tab.

The default program on your computer that is attached to files with *.csv extensions is Excel. If you double-clicked on the file to open it in Excel, Excel would separate the data into columns as defined by where the commas are located. The *.csv file is created in Excel using a Save As command in the File menu. Note that only one worksheet at a time can be saved as a *.csv file.

The second key item is to choose whether there are column headings in the top row. In the context of reading data, these column headings would mean the name of the variables.

  • Once the data are read successfully, your Global Environment space displays the name of the data frame, the number of observations, and the number of variables. You can type ls() in your Console to see what is now present.

  • You can see the commands needed to bring the file into the workspace in the History tab on the top right in RStudio.

  • You can review some of the features of the Global Environment space in Section 2.