Importing Data Sets into R Studio

Data sets that are saved on your local computer can exist imported into R. If the information set is posted on a website, starting time salve it to your local computer and and so import it.

The Traditional Way (harder)

The older method for importing information sets in to employ the read.csv(file.choose()) command. If I were to enter the line of code below into the Console window at the lower correct, without a file name in the inner parentheses and and so hit the Enter cardinal, it would open a dialog box that allowed me to locate the file on my local computer.

Note that the window may not fully open, but might appear on your taskbar at the lesser of your screen if you lot are using a PC (run across the dark-brown highlghted selection on my taskbar in the paradigm below.

If you click on the highlighted choice on the taskbar, information technology will open the dialog box in the previous epitome, and you can browse to locate and select the data file.

One time you double click on the data file to select information technology, it will import the data set and give it the nickname "fram" in this case, a nickname that I chose only to allow less typing when referring to the information fix. Then, to view the data gear up in the upper left window, you can use the control View(fram), noting that this particular commaned uses an capital letter "V", although most are lowercase.

The Easy Way to Import Information

The easiest way is to click on the "Import Data set" push button in the upper right window of R Studio. A pop-down menu will open. If you are importing a .CSV file, choose the first option (From text(base of operations)).

Choose the first menu option

This will open some other window enabling you to scan your calculator to locate the file you desire to import. Double click on the file, and another window will open up as shown below.

Does the Data Have Headings?

On the left side there is an option to indicate whether the information set has Headings (variable names at the height of the columns). All of the PH717 information sets take headings, so make sure "Yes" is selected. Then click on the "Import" button at the bottom of this window.

Viewing the Data Prepare

When the information is imported, R should show the information in the upper left window of the R Studio, and you can gyre right and left and up and downwards to check the information set for errors. Notice likewise that R has created a tab just below the principal card with the title for the data set (framstudy in this case).

The data set is also now listed in the window at the upper right and indicates that it has 49 observations and half dozen variables.

You can review the data set at any time by clicking on the tab with its name in the upper left window or by clicking on the data set name in the upper right window. You can also review it using the "View()" control in R, e.g., View(framstudy) and and then hitting the "Run" push button in the upper left window. Note that this R command uses an majuscule "V", although most commands apply lower example.

Issues Importing Data Sets

  • Importing .CSV files using a PC is generally not a trouble, although occasionally there are bug if 1 is using Chrome every bit their browser. If and so, try using Safari or Firefox.
  • Students using Macs sometimes have difficulties that vary with the age and type of computer they are using. When downloading a data set up to a Mac, sometimes the extension for the data file gets changed to .txt or another file type. Make sure that the saved file has a .CSV extension. Some of these download problems are solved by downloading using Chrome every bit your browser instead of Safari.
  • Some other pick is to download the data file as an .XLSX file, and and so import it as an XLSX file into RStudio (third choice on the Import dataset drop down bill of fare).
  • In rare cases, I have had to e-mail data sets to students as .CSV files. Once they save them on their local computer, they have been able to import them into R.

Importing Information from Excel Spreadsheets (.XLSX files) on a PC or Mac

All of the data sets for PH717 are .CSV files, merely you tin import data from .XLSX files. Once over again, employ the "Import Dataset" push in the upper right window in R Studio, simply select the third option (From Excel).

This will open up a window that enables yous to browse for the data file you lot desire. One time y'all locate it, click to select it so click on the "Import" button at the lesser.