R-Studio Code for Intro to Statistics, Modules 1-3 Flashcards
What is the code used to set the working directory for the RStudio file?
setwd(“C:/Users/Joseph Paoli/Downloads/Lessons in R for Stats/ Module ___”)
What is another way to set the working directory in RStudio which involves the lower-right panel of the user interface?
Describe it in three steps.
- Click the “Files” tab in the lower-right panel, which is next to “Plots”.
- In the tab below the blue gear, find the correct folder desired for the working directory.
- Click on the blue gear at this point to open the drop-down menu, then select “Set As Working Directory”.
What is the code used to start off RStudio with a blank environment?
rm(list=ls())
We want to create a random sequence of 100 numbers, each of which is between 1 and 20, and we want to call this object “random_numbers”.
What is the RScript code to do this?
random_numbers=runif(100, 1, 20)
We want to see a summary of the object “random_numbers” (a set of 100 random values between 1 and 20).
What is the RStudio code?
summary(random_numbers)
We want to see a histogram of the object “random_numbers” (a set of 100 random values between 1 and 20).
What is the RStudio code?
hist(random_numbers)
What six statistics are provided when you run the “summary” command?
Minimum Value
1st Quartile
Median
Mean
3rd Quartile
Maximum Value
If we generate a histogram and want to save it as an image file to our working directory, how would we do this?
In the “Plots” tab, select the drop-down menu titled “Export” and select “Save as Image…”, then name the file accordingly.
We want to save out the summary statistics from the object “random_numbers”, so that we can use the data to make a table for a later report. We will save it out as an XLS file with the title “rando_values”.
What is the RStudio code to do this?
capture.output(summary(random_numbers), file=”rando_values.xls”)
What are the two different ways to call in a dataset in RStudio, assuming the data is in a CSV file format and has the name “TestData.csv”?
- In the “Environment” tab in the upper-left, select the drop-down menu for “Import Dataset”, then select “From Text (base)…”, at which point a sub-window will open displaying the working directory where the CSV file should be located.
- We can type the ‘read’ command in the script editor, which would look something like this:
test_data=read.csv(“TestData.csv”)
We have a dataset called “data” which includes nine observations with the following values:
1 1 1 3 5 7 9 14 23
We want to remove all values less than four to create an abbreviated list which is called “modData”.
What is the RStudio code?
modData=data[(data>4)]
We want to log-transform the values in the “modData” values.
What is the RStudio code?
log_modData=log(modData)
We want to square root-transform the values in the “modData” values.
What is the RStudio code?
sqrt_modData=sqrt(modData)
We want to find the average of the set of values in “modData”.
What is the RStudio code?
mean(modData)
We want to find the variance of the set of values in “modData”.
What is the RStudio code?
var(modData)
We want to find the standard deviation of the set of values in “diam_1983” column of the “tree_diam” data set.
We want to find the standard deviation
We want to install and load the package “COBRA” using the RScript Editor. COBRA is a standard set which is found in RStudio at the time of RStudio’s download.
What are the two lines of code in RStudio to do this?
install.packages(“COBRA”)
library(COBRA)
Let’s say we have the command “read.table” and we want RStudio to tell us more about how to use it. What is the appropriate code to type in the RScript Editor?
?read.table