Week 1 Flashcards

1
Q

library()

A
  • List of all packages installed on your computer
  • displayed in R editor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

search()

A

List of all packages currently active on your computer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

install.packages(“< lib_name >”)

A
  • package is downloaded from CRAN and installed on your computer
  • also in Tools Menu (RStudio)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

library(“< lib_name >”)

A
  • loads the library
  • used after install.packages(_)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

library(help = “< lib_name >”)

A

package documentation listed in editor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

update.packages ()

A
  • updates all packages
  • also in Tools Menu (RStudio)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

detach(“ package:< lib_name> “, unload=TRUE)

A
  • Package is removed
  • Package can also be removed from the right hand side window
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Task

Clear the console

A
  • Edit -> Clear Console
  • Ctrl + L
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

comments

A
  • start with #
  • single lines only
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

run single command from script

A
  • Ctrl + Enter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

index number

A
  • first number displayed in [ ]
  • indexes start at 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

print(“string”)

A
  • prints string and quotes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

assignment operator

A
  • <-
  • can also use =
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

display variable value

A

type variable name in editor and execute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

concatenate vectors

A

c(x,y) = x values, y values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

multiple vectors subtraction

A

performs operation on values of same index

  • x <- 5,5,5
  • y <- 1,2,3
  • x - y = 4,3,2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

vector multiplication

A

y * 3 = each value in y vector x 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

table commands

dim(table_name)

A
  • gives dimensions of table
  • rows then columns
19
Q

summary(table_name)

A
  • gives summary stats for each column
  • min, 1st quart, median, mean, 3rd, quart, max
20
Q

head(table_name)

A

prints first 6 rows of table

21
Q

names(table_name)

A

prints column headers / names

22
Q

table( table_name $ column_name )

A
  • 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
23
Q

pie(table(table name $ table column)

A
  • creates pie chart for counts of each value in specified table column
24
Q

pie(table(iris$Species ), col= purple”,”red”,”green”

A

assigns pie chart colors to each iris species in same order species are listed

25
variable names | rules
- case-sensitive - can't begin with number or symbol - no blank spaces - can use period (eg. abc.x)
26
vector creation | methods (3)
1. Concatenate (c) 2. Sequence (seq) 3. Repeat (rep)
27
# vector creation concatenate
- c( ) - eg. y <- c(2,3,5,6) - x <- c(first = "alpha", second="beta", third="gamma")
28
# concatenate order of restriction for conversion (Least to most restrictive)
1. Strings 2. Numerics 3. True/False
29
repeat function rep(...)
used to create vector with repeating pattern - v = c(11,22,33) - x = rep(v,3) 11 22 33 11 22 33 11 22 33 - gender = c("male","female") - y = rep(gender,c(2,5)) "male" "male" "female" "female" "female" "female" "female"
30
vector value assignment
assigning nonexistent value to vector, matrix, array, or list expands structure to accomodate new value - x < c(8,6,4) - x[7] < 10 - x = 8 6 4 NA NA NA 10
31
# repeat function array declaration
- n <- 10 - y < rep (0,n) - y = 0 0 0 0 0 0 0 0 0 0
32
R Data Input | Sources (5)
1. Text Files (eg. ASCII, XML, webscraping) 2. Statistical Packages (eg. SPSS, SAS, Stata) 3. Keyboard 4. Database Management Systems (eg. MySql, Oracle, Access) 5. Other (eg. Excel, NetCFD, HDF5)
33
# Import / Export Flat Files
**Import** - AHW < read.csv(“AHW_1.csv”, header=TRUE) - weatherdata <-read.table (file="C:/work/DM1/weather.csv", header=TRUE, sep=",") **Export** write.table(z,"D t RDataFiles Output z.txt")
34
# Import / Expoort Databases
**Import** connection < dbConnect (driver, user, password, host, dbname AHW < dbSendQuery (connection, “SELECT * FROM AHW") **Export** connnection <- dbConnect (driver, user, password, host,dbname dbWriteTable (connnection , “AHW”, AHW)
35
# Import / Export R objects
- **Import**: > load(‘AHW.Rdata') - **Export**: > save(AHW, file= “New_AHW.Rdata")
36
# Import Web
connection <- url (‘http://pace.sdsc.edu/sites/bootcamp/images/AHW_1.csv') AHW <- read.csv(connection, header=TRUE)
37
How to enter data in R | 5
1. **Sequential Data**: assignment operator and vector definition (x = 1:5) 2.** Non-sequential Data**: concatenation operator 3. **List Objects** 4. **Read a CSV** 5. **Structure**: provides info about data frame
38
ls()
displays list objects eg. x = 5, y = 3 ls() = "x" "y"
39
Read data from a spreadsheet | process
1. convert spreadsheet to .csv file 2. variable -< read.csv("Path") - need forward slash or 2 back slashes in path - example variable name: sn.csv
40
str(csv_variable)
- provides details of Data frame from csv file -
41
# Data input keyboard | example
mydata <- data.frame (age=numeric(0), gender=character(0), weight=numeric(0)) mydata <- edit( mydata)
42
Data Types
1. Vector (1 dimensional) 2. Matrix (2 dimensional) 3. Array (3 dimensional) 4. Data Frame - Column can be different modes 5. List - Vectors, matrix, arrays, data frames, lists
43
Data Frame
- More general than a matrix - Different columns can contain different modes of data - concatenate values for individual columns variable <- data.frame(column1, column2, column3, etc)
44
Specifying Data Frame Elements
- patientdata [1:2] = all rows of 1st 2 data columns - patientdata [ diabetes","status"]) = all rows of specified columns - patientdata$age = all values in age column (without header)