Reating A Project IN Tudio: Steps
Reating A Project IN Tudio: Steps
This exercise requires that you create and use a project in RStudio.
Steps
g. Click on New folder; create the following five folders in the Files pane:
Data
Code
Documents
Output
Plots
h. Copy the file Diamonds.csv data into the Data folder of the project.
i. Open a new script file: File > New File > RScript.
3
j. Copy and paste the following code into the script pane of RStudio (usually the
pane in the upper left).
getwd()# Check the default directory.
diamonds <- read.csv("./Data/Diamonds.csv")# Read Diamonds.csv into diamonds.
head(diamonds,10) # Print out the first 10 rows.
tail(diamonds,10) # Print the last 10 rows
#
summary(diamonds) # Summarize the data in diamonds.
#
#### Subset the data to include only observations where carets <= 2.5.
diamonds <- diamonds[which(diamonds$carat <= 2.5),]
#
#
summary(diamonds) # Run the summary again.
#
hist(diamonds$carat) # Produce a histogram of the carat sizes.
# Save the plot your project Plots folder.
dev.copy(jpeg,'./Plots/carat_hist.jpg', width = 800, height = 600)
dev.off() # Turn off the output to files.
#
table(diamonds$clarity) # Produce a table of the clarity values.
#
#### Install the following ggplot2 on your computer.
#### (You may be asked to select a repository; any repository will work,
#### if you select one geographically close, things will go faster.