Loading datasets into r Studio

You can load any dataset into rStudio.

Creating datasets

Create the dataset in a spreadsheet such as excel or Google sheets. The dataset must be tidy data. That means that each row belongs to one unit of observation, the columns contain each distinct variable, and all the variable names are one word. It is suggested that they are lowercase and describe what the variable is for the dataset. If you want to have a space in the name of the variable, use _ instead of a space. Then save the file as a csv file using the name of the file without spaces in the file name.

Reading in a dataset into r Studio

Uploading Datasets

In rStudio, in the pane that has the Files, Plots, Packages, Help, Viewer, click on the files tab. In the Files tab, click on Upload and find the file on your computer. Say OK. Under Files find the file you uploaded, click on it, and then click on Import Data set. Copy the File/URL address in the Import Text Data window. Cancel out of this window and either in the Console or in an r Markdown file insert the following command:

Dataset_name <- read.csv(“paste File/URL address”)

If you load a dataset into your r Markdown file, make sure you place the command in the setup r chunk at the beginning of your document. When one reads in a dataset the dataset shows up in the global environment.

Reading a dataset into r Studio from a website

You can also post the dataset to a website such as git hub and then read the dataset in this way. As an example the dataset fav_color_data.csv is save on a git hub. to read this in using this command:

Favcolor <- read.csv("https://krkozak.github.io/MAT160/fav_color_data.csv")

Reading a dataset in from a package

If you are using a dataset that is in a package, you can use it without the dataset being in the global environment. If you want it in the global environment use this command if you want to read in the NHANES dataset:

NHANES<-NHANES

You do similar commands for other datasets that are parts of packages. If you want to clear the global environment or the console, click on the yellow broom at the top right of the pane.