Week 1 Flashcards
library()
- List of all packages installed on your computer
- displayed in R editor
search()
List of all packages currently active on your computer
install.packages(“< lib_name >”)
- package is downloaded from CRAN and installed on your computer
- also in Tools Menu (RStudio)
library(“< lib_name >”)
- loads the library
- used after install.packages(_)
library(help = “< lib_name >”)
package documentation listed in editor
update.packages ()
- updates all packages
- also in Tools Menu (RStudio)
detach(“ package:< lib_name> “, unload=TRUE)
- Package is removed
- Package can also be removed from the right hand side window
Task
Clear the console
- Edit -> Clear Console
- Ctrl + L
comments
- start with #
- single lines only
run single command from script
- Ctrl + Enter
index number
- first number displayed in [ ]
- indexes start at 1
print(“string”)
- prints string and quotes
assignment operator
- <-
- can also use =
display variable value
type variable name in editor and execute
concatenate vectors
c(x,y) = x values, y values
multiple vectors subtraction
performs operation on values of same index
- x <- 5,5,5
- y <- 1,2,3
- x - y = 4,3,2
vector multiplication
y * 3 = each value in y vector x 3
table commands
dim(table_name)
- gives dimensions of table
- rows then columns
summary(table_name)
- gives summary stats for each column
- min, 1st quart, median, mean, 3rd, quart, max
head(table_name)
prints first 6 rows of table
names(table_name)
prints column headers / names
table( table_name $ column_name )
- makes a new table with the counts for each value type (new headers) in specified column
- eg. table(iris$species) = setosa 50 versicolor 50 virginica 50
pie(table(table name $ table column)
- creates pie chart for counts of each value in specified table column
pie(table(iris$Species ), col= purple”,”red”,”green”
assigns pie chart colors to each iris species in same order species are listed