Introduction to R Flashcards

1
Q

Assignment

A

-

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

help(Syntax)

A
  • Function with argument that lists all of the operators in R.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

mode()

A
  • Function without argument that revels storage.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

typeof()

A
  • Function without argument that reveals type of object.

- Similar to is(argument) function.

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

setwd()

A
  • Function without argument that changes your working directory.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

getwd()

A
  • Function without argument that gets the current file path of your working directory.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Object

A
  • A storage space with an associated name.

- Everything in R is stored as an object.

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

Object Naming Protocols

A

1) Case sensitive names.
2) Must start with a period or letter.
- If starts with a period, a letter must follow.
3) Periods can be found anywhere in an R name but the underscore cannot start a name.
4) Names cannot have spaces.
5) Names almost never take quotes around them.

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

Functions

A
  • A special type of R object that exist / are created to do something.
  • Usually take arguments but can also have no arguments.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Vectors

A
  • An ordered sequence in R.
  • No scalars exist in R = a single value is an vector of length 1.
  • [1] denotes the first element on a vector in R.
  • Two types: atomic and generic vectors.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Atomic Vectors

A
  • A vector containing only one data type.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Generic Vectors (Lists)

A
  • A vector that can contain more than one data type.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Generating Vectors

A
  • Can use two different functions:
    1) seq()
    2) c()
    3) :
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

:

A
  • Known as the colon operator.
  • Generates a sequence from:to in steps of 1.
  • Can be in either increasing or decreasing order.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

seq()

A
  • Known as the sequence function.
  • Format of seq(from,to,by).
  • Technically constructed as seq (from = a, to = b, by = c) but this is long.
  • Can be in either increasing or decreasing order.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

c()

A
  • Known as the concatenate function.
  • Combines / concatenates values into a vector.
  • Output type determined by the highest type among vector components and follows the rule: character > integer > logical.
    1) If any value is a character, the vector becomes a character vector.
    2) If no characters, and a mix of integer and logical, becomes an integer vector where logicals are converted into integers.
17
Q

class(argument)

A
  • Known as the class function.

- Gives the data type of the vector.

18
Q

vector1[vector2]

A
  • Selects elements of vector1 whose indices are given by vector2.
  • vector2 is known as the index vector.
19
Q

Matrix

A
  • An atomic vector with row and column indices.
  • All rows and columns must be of the same size but can have different # of row and columns.
  • Elements accessed via indexing.
20
Q

Accessing Matrix Elements (Few Examples)

A

1) objectname[r,c] = access a specific cell.
2) objectname[r,] = access all columns of a specific row.
3) objectname[,c] = access all rows of a specific column.

21
Q

dim(argument)

A
  • Known as the dimension function.

- Gives the dimension of a matrix input.

22
Q

is.matrix(argument)

A
  • Gives the data type of the matrix.
23
Q

rowbind(argument)

A
  • Function that assigns names to the rows, starting from row #1.
24
Q

cbind(argument)

A
  • Function that assigns names to the columns, starting from column #1.
25
Q

outer(argument, argument)

A

-

26
Q

nrow(argument)

A
  • Function that gives the number of rows of a matrix.
27
Q

ncol(argument)

A
  • Function that gives the numbers of columns of a matrix.
28
Q

Properties of Lists

A
  • Can contain any type of R object.
  • May have mixed elements = not atomic.
  • List elements can be separated out and saved as new lists, new vectors, etc.
29
Q

list(argument,argument,…)

A
  • Function that creates a list where the arguments are stored in the list elements.
  • Access the elements using [[indices]] or [indices].
30
Q

Data Frame

A
  • A rectangular list.
  • Has “observations” in the rows and “variables” in columns in a rectangular matrix-like structure.
  • row.names(put_in_names) = labels the rows.
  • column.names(put_in_stuff) = labels and columns.
  • Can access using matrix indexing rules ([]) or list indexing rules ([[]]).
31
Q

class(object)

A
  • Function that outputs the class of an object.
32
Q

names(object)

A
  • Function (mainly used with data frames) that outputs the names of the columns (?) data frame.
33
Q

str(object)

A
  • Function that gives the structure of an object.
34
Q

head(object)

A
  • Function that gives the first few rows of the object.
35
Q

summary(object)

A
  • Function that gives some statistics about an object.
36
Q

Data Frame Extraction (Columns)

A
  • Use a combination of extraction operators [], [[]] and $ and column names when necessary (with $).
37
Q

install.packages(“package”)

A
  • Function that finds and installs a desired function in R.
38
Q

library(package)

A
  • Function that calls an installed package before use.

- Must call the package once before you can utilize their functions.