R-Code for Exam, Modules 1-8 Flashcards
sd(DATASET_NAME$VARIABLE_NAME)
gives the standard deviation for the observations in the variable
favstats(DATASET_NAME$VARIABLE_NAME)
provides summaries of the observations in the variable
hist(DATASET_NAME$VARIABLE_NAME)
produces a histogram of the variable from the dataset
boxplot(DATASET_NAME$VARIABLE_NAME)
produces a boxplot of the variable from the dataset
boxplot(Y~X, data = DATASET_NAME)
produces a box-plot for variable “Y” given variable “X” from the dataset
summary(DATASET_NAME)
gives numerical summaries of all of the variables in the data set
(minimum, maximum, median, mean, 1st quartile, 3rd quartile)
t.test(Y~X, data = DATASET_NAME, conf.level = 0.95)
provides a two-sample t-test statistic, degrees of freedom, and p-value for a 95% confidence interval
runif(# OBS, X, Y)
produces a list of random numbers in the range (X, Y), with the number of observations specified by “# OBS”
setwd(“C:/Users/Joseph Paoli/Downloads/Lessons in R for Stats”)
sets the working directory for “Lessons in R for Stats” in the Downloads folder
rm(list=ls())
sets a clean working environment in RStudio
“Flies” → Desired Folder (Click) → Blue Gear (Click) → “Set as Working Directory”
how to set the working directory if the RStudio code doesn’t work
“Plots” → “Export” → “Save as Image…”
how to export a plotted graph in the viewing area to a .jpeg or .png file
capture.output(summary(DATASET_NAME), file = “EXCEL_NAME.xls”)
saves the summary statistics for a dataset as an Excel file of a specified name
data[(DATASET_NAME > X)]
modifies the dataset to include only values greater than “X”
log(DATASET_NAME)
takes the common log (base-10) of the dataset
sqrt(DATASET_NAME)
takes the square root of the dataset
var(DATASET_NAME)
finds the variance in the set of values in the dataset
install.packages(“PACKAGE”)
installs a package called “PACKAGE” into RStudio
library(“PACKAGES”)
loads the package “PACKAGE” for our use in RStudio
?rstudio.command
this code would provide information on the command with the name “rstudio.command”
help.search(“data.input”)
command which would locate a code for imputing data into RStudio unknown to the user
find(“rstudio.command”)
there’s a command called “rstudio.command” which you know the name of and want to use, but you don’t know the package it’s located under
example(rstudio.command)
we want to run an example of the command “rstudio.command” to become better acquainted with it
demo(graphics)
generates a series of plots and shows the code to make them in the “Console” window in the lower-left of RStudio
colnames(DATASET_NAME)
provides the names of all of the columns in a data set
dim(DATASET_NAME)
provides the number of columns and the number of rows in the data set
str(DATASET_NAME)
provides the internal structure of the data set
range(DATASET_NAME$VARIABLE_NAME)
provides the range in values of a certain variable from the dataset
quantile(DATASET_NAME$VARIABLE_NAME, X%)
provides the X% quantile of a certain variable from the dataset, which is to say that X% of the other observations are below it and (100-X)% of the observations are above it (“X%” is expressed in decimal form, not as a percentage)