Import a CSV file into R-Studio

Start R-Studio. R-Studio is a “graphical user interface” (GUI) to the R statistics environment. You can run R straight from the “command line interface” (CLI) or “console window”, but that is hard because it is difficult to see if anything is happening, and any typo will cause an ERROR output. The good news with R-Studio is that we can sketch out commands, keep tying them until they work, take notes on what they do and what can go wrong, and save all those notes and working commands as separate text-files for future use. One of the profound differences between using command-line software in the 21st century (in contrast tot he 1970s) is that you can use a web-browser to search for solutions to problems, copy the problem-solving command directly from a web-page into R-Studio, run it as a command, but also save it (with explanatory comments) as a freestanding text file for future reference.

Let’s get some data into R-Studio. Begin in the upper-right (“Workspace”) pane:

R Studio up and running. Now pick “Import Dataset -> From Text File.”

In the dialog box that opens, navigate to ~/soc393/census/ and find your “master” CSV file, compiled from several different Census tables. (Creation of the “master” CSV is on a separate page). When you select it, the “Import Dataset” Dialog (below) opens. Review the Input File preview to make sure that it is the data you want to import.

Specify an name for your imported dataset, and specify that Line 1 does indeed contain Heading data.
Specify an name for your imported dataset, and specify that Line 1 does indeed contain Heading data.

In the screenshot above, Chris proposed an extremely short name for the dataset: “SF”. I recommend naming the new data-frame as CO. Whenever you create an object-name in R, avoid using hyphens and spaces. (Detailed naming-conventions on a separate page).

08_R_imported-data

Now, the CSV data for your county is loaded into this session of R Studio. Several things to note in the red-circled areas:
1) The Source pane (top-left) shows the data in table format. It is always useful to review your raw data, just for a reality-check. However, this view of your data will persist even if the origina data-frame is removed, so the existence of this view does not mean that your data is still there.
2) The lower-right “Console” pane shows the command that we executed. In technical terms, R Studio “passed” this command to the R “environment”. We didn’t need to type it, because we clicked buttons to import the CSV file. As a graphic front-end to R, R-Studio translated clicks into specified text commands.
3) The Workspace pane (upper-right) gives us some summary data on the imported file. In R, the columns are called “variables” and the rows are called “observations” (obs.).

Scroll to Top