TERMS
conditional statement - a command containing a conditional operator that evaluates to either TRUE or FALSE
== conditional operator; "is equal to"
!= conditional operator; "is not equal to"
> conditional operator; "is greater than"
>= conditional operator; "is greater than or equal to"
< conditional operator; "is less than"
<= conditional operator; "is less than or equal to"
| conditional operator; "or"; expects conditional statements on either side of the operator. Both sides of the | must be FALSE for this to evaluate to FALSE
& conditional operator; "and"; expects conditional statements on either side of the operator. Both sides of the & must be TRUE for this to evaluate to TRUE
mode - the inherent 'type' of a variable; we'll work mostly with numeric (numbers, integer or real), character (text), and logical (TRUE or FALSE)
class - the 'organization' of the data contained in a variable. The default for simple scalar or vector data is for the class to be the same as the mode. Other classes that we will see are: matrix, data.frame, ts (time series).
coerce - forcing a variable to change its mode. This really only works in cases where it makes sense for the data to be in a different type of mode. (e.g. a character "46" can become a numeric 46, a matrix of numerics can become a data frame)
vector - one unit of data that contains many elements of the same mode. Describe a vector by its length and the mode of data contained (e.g. "a three element numeric vector").
elements - the individual pieces of a vector
index - the location of an element within a vector (i.e. the 5th element has an index of 5)
vectorization - an inherent property of R that allows faster and more flexible operations on data that have dimensionality (e.g. vectors and matrices as opposed to scalars). Since R can tell whether data are vectors or scalars, R determines how to efficiently perform operations on whatever data it encounters (performing the operation on each element of a vector, or performing an operation on two vectors that are matched element for element for instance)
FUNCTIONS
c(...) - "concatenate"
Arguments: any number of arguments that are the same mode
What does it do: combines arguments into a vector
What does it return: a vector
seq(from, to, by) - "sequence"
Arguments: from (the starting number), to (the finishing number), by (the number to count by)
What does it do: concatenates the integers starting with the 'from' argument and going to the 'to' argument, counting by the 'by' argument
What does it return: a vector
Example: seq(from=1, to=9, by=2) returns c(1, 3, 5, 7, 9)
mode(x) and class(x)
Arguments: any variable
What does it do: determines the mode or class of that variable
What does it return: character
as.numeric(x), as.matrix(x), as.data.frame(x)
Arguments: any variable
What does it do: tries to coerce the variable to a numeric, matrix, or data frame
What does it return: a numeric, matrix, or data frame
mean(x, na.rm = FALSE) and sd(x, na.rm = FALSE)
Arguments: x (any numeric variable), na.rm=FALSE (a logical determining how NAs are handled)
What does it do: calculates the mean or standard deviation of the vector and ignores NAs if na.rm is set to TRUE
What does it return: a numeric or NA (if there are any NAs present and na.rm is FALSE, the default)
str(object) - "structure"
Arguments: any variable
What does it do: determines the structure of the variable
What does it return: a short description of the modes and classes contained in the variable, as well as a preview of the first several elements
length(x)
Arguments: a vector or matrix
What does it do: determines how many elements are in the variable
What does it return: a scalar numeric
dim(x)
Arguments: a data frame or matrix
What does it do: determines how many rows and columns are in the variable
What does it return: a two-element numeric vector representing the number of rows in the variable as the first element and the number of columns as the second.
conditional statement - a command containing a conditional operator that evaluates to either TRUE or FALSE
== conditional operator; "is equal to"
!= conditional operator; "is not equal to"
> conditional operator; "is greater than"
>= conditional operator; "is greater than or equal to"
< conditional operator; "is less than"
<= conditional operator; "is less than or equal to"
| conditional operator; "or"; expects conditional statements on either side of the operator. Both sides of the | must be FALSE for this to evaluate to FALSE
& conditional operator; "and"; expects conditional statements on either side of the operator. Both sides of the & must be TRUE for this to evaluate to TRUE
mode - the inherent 'type' of a variable; we'll work mostly with numeric (numbers, integer or real), character (text), and logical (TRUE or FALSE)
class - the 'organization' of the data contained in a variable. The default for simple scalar or vector data is for the class to be the same as the mode. Other classes that we will see are: matrix, data.frame, ts (time series).
coerce - forcing a variable to change its mode. This really only works in cases where it makes sense for the data to be in a different type of mode. (e.g. a character "46" can become a numeric 46, a matrix of numerics can become a data frame)
vector - one unit of data that contains many elements of the same mode. Describe a vector by its length and the mode of data contained (e.g. "a three element numeric vector").
elements - the individual pieces of a vector
index - the location of an element within a vector (i.e. the 5th element has an index of 5)
vectorization - an inherent property of R that allows faster and more flexible operations on data that have dimensionality (e.g. vectors and matrices as opposed to scalars). Since R can tell whether data are vectors or scalars, R determines how to efficiently perform operations on whatever data it encounters (performing the operation on each element of a vector, or performing an operation on two vectors that are matched element for element for instance)
FUNCTIONS
c(...) - "concatenate"
Arguments: any number of arguments that are the same mode
What does it do: combines arguments into a vector
What does it return: a vector
seq(from, to, by) - "sequence"
Arguments: from (the starting number), to (the finishing number), by (the number to count by)
What does it do: concatenates the integers starting with the 'from' argument and going to the 'to' argument, counting by the 'by' argument
What does it return: a vector
Example: seq(from=1, to=9, by=2) returns c(1, 3, 5, 7, 9)
mode(x) and class(x)
Arguments: any variable
What does it do: determines the mode or class of that variable
What does it return: character
as.numeric(x), as.matrix(x), as.data.frame(x)
Arguments: any variable
What does it do: tries to coerce the variable to a numeric, matrix, or data frame
What does it return: a numeric, matrix, or data frame
mean(x, na.rm = FALSE) and sd(x, na.rm = FALSE)
Arguments: x (any numeric variable), na.rm=FALSE (a logical determining how NAs are handled)
What does it do: calculates the mean or standard deviation of the vector and ignores NAs if na.rm is set to TRUE
What does it return: a numeric or NA (if there are any NAs present and na.rm is FALSE, the default)
str(object) - "structure"
Arguments: any variable
What does it do: determines the structure of the variable
What does it return: a short description of the modes and classes contained in the variable, as well as a preview of the first several elements
length(x)
Arguments: a vector or matrix
What does it do: determines how many elements are in the variable
What does it return: a scalar numeric
dim(x)
Arguments: a data frame or matrix
What does it do: determines how many rows and columns are in the variable
What does it return: a two-element numeric vector representing the number of rows in the variable as the first element and the number of columns as the second.