1/27
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
vector (what is it? how is one created?)
A vector is a sequence of data elements of the same data type.
It is created using the c() function.
RStudio: c() function (what does it do? what does the "c" stand for?)
The c() function is used to create or combine vectors.
The "c" stands for "combine".
coercion (what is it? when does it occur? You do not need to know the priority order for converting data types)
Coercion is the automatic conversion of one data type to another.
It occurs when you attempt to combine vectors of different data types into a single vector, as vectors must be homogeneous.
math operations with vectors (Know how mathematical operations between
vectors and scalars are evaluated by R;)
Vector and Scalars: Mathematical operations (like +, -, or ^) between a vector and a scalar are performed on each individual element of the vector.
Know how mathematical operations between two vectors are performed; how does R perform vector math with vectors of different sizes? what is vector recycling?)
Two Vectors: Operations between two vectors of the same size are performed on all corresponding elements of each vector.
Different Sizes/Vector Recycling: If vectors have different lengths, the shorter vector is lengthened by repeating its elements (element-by-element) to match the length of the longer one; this is known as vector recycling.
accessing individual elements of a vector (how? how to provide a particular
element's index? how to specify a range of indexes?)
Elements are accessed by specifying the index inside square brackets [ ] following the variable name.
To specify a range of indexes, use the colon operator : inside the brackets (e.g., MyVec[1:5]).
data frame (what is it? how many dimensions? homogeneous or
heterogeneous? what do columns represent? what do rows represent? )
A data frame is a two-dimensional data structure (rows and columns).
It is heterogeneous, meaning while each column must be homogeneous, different columns can contain different data types.
Columns represent variables, and rows represent observations on those variables.
Names: Change column names using the names() function and row names using the row.names() function. You can change a single column name by specifying its index (e.g., names(DF1) <- "NewName").
how to change row/column names? accessing variable/column in data frame? accessing row? accessing variable by name in data frame?
Names: Change column names using the names() function and row names using the row.names() function. You can change a single column name by specifying its index (e.g., names(DF1) <- "NewName").
Accessing: Access a column as a data frame using brackets (e.g., DF1) or as a vector using $ notation (e.g., DF1$Age). Access specific values using [row, column].
how to add/delete rows/columns from data frame? methods for finding number of rows/columns in data frame?
Add/Delete: Add rows with rbind() and columns with cbind(). Delete them by using a negative sign with the c() function inside brackets (e.g., DF2[-c(1), ] deletes the first row).
Row/Column Count: Use nrow() for rows and ncol() (or length()) for columns. dim() returns both.
RStudio: data.frame() function (how to use? how to create an empty data frame? how to assemble existing vectors into data frame?)
This is used to create a data frame.
To create an empty data frame, use data.frame() with no arguments.
It can assemble existing vectors into a data frame by passing them as arguments.
RStudio: rbind() function (what does it do? how to use?)
rbind() (row bind) adds a new row to an existing data frame.
RStudio: cbind() function (what does it do? how to use?)
cbind() (column bind) adds a new column.
RStudio: nrow() function (what does it do?)
nrow() returns the number of rows in a data frame
RStudio: ncol() function (what does it do?)
ncol() returns the number of columns.
RStudio: edit() function (what does it do?)
This opens a spreadsheet-like data editor to enter or edit values.
You must assign the output of the function back to your variable (e.g., DF <- edit(DF)) to save the changes.
RStudio: sum() function (what does it do? Be able to use it properly given a
summation in standard summation notation; how can it be used with a range of values in vector? how can it be used with a data frame column? How can it be used with data frame "$" notation to access variable?)
This function adds the elements of a vector.
Summation Notation: It can be used for expressions like Σx^2 by typing sum(X^2) or Σ(x−1) by typing sum(X-1).
Ranges: It can sum a specific range in a vector using the colon operator (e.g., sum(MyVec[1:7])).
Data Frames: It can sum a column by index (e.g., sum(DF1)) or by name using $ notation (e.g., sum(DF1$Age)).
RStudio: length() function (what does it do? how to use with a vector?)
This returns the number of elements in a vector, which is useful for finding N (the number of scores).
RStudio: cat() function (what does it do? what does the "\n" escape character do, and how do you use it? I won't ask about the "sep" parameter)
Short for "concatenate," it prints out combined text and variable values.
The \n escape character inserts a new line into the output.
RStudio: format() function (what does it do? what does the "digits" parameter
do? What does the "nsmall" parameter do? What does the "big.mark" parameter do? I won't ask about the "scientific" parameter)
Used to format numbers or strings to improve readability; it returns a formatted character string.
digits parameter: Sets the number of significant digits.
nsmall parameter: Sets the minimum number of digits to the right of the decimal.
big.mark parameter: Adds separators (like commas) to large numbers (e.g., big.mark=",").
RStudio: read.csv() function (what does it do? What kind of data structure does the data get loaded into?)
This loads the contents of a CSV file into a data frame in your workspace.
working directory (what is it? )
The working directory is the specific folder that R uses as its starting point when searching for files to open (like data sets) or when saving output files.
The working directory is the starting folder R uses when searching for files or saving output.
how to "get" and "set" your working directory?
Setting a working directory allows you to access files by just their filename instead of typing out a long, full file path.
How to "get" it: You can find the path to your current working directory by entering the getwd() function in the console.
How to "set" it:
Console Method: Use the setwd(path) function (e.g., setwd("c:/10A/HW02")).
Output Pane Method: Under the Files tab, navigate to your desired folder, click the More button, and select "Set As Working Directory".
RStudio: getwd() and setwd() (what does they do?)
getwd(): This function returns the current file path of the folder R is currently using as its working directory.
setwd(): This function changes the current working directory to the specific folder path provided as an argument.
Use getwd() to see the current path and setwd("path") to change it.
default working directory (I won't ask how to set your default working director
The default working directory is the folder RStudio automatically opens to whenever the application is launched.
Any changes you make to your "current" working directory during a session are temporary; whenever you close and restart RStudio, it resets back to the default working directory.
RStudio: rm() function (what does it do? how to use with multiple variables?)
rm() removes specific variables from the global environment. You can remove multiple variables by separating them with commas.
RStudio: "broom" button in Environment pane (what does it do?)
The "broom" button in the Environment pane removes all variables from the workspace.
retyping previously-entered commands at console (different methods?)
You can double-click commands in the History tab of the Environment pane to retype them into the console.
Alternatively, use the "Up Arrow" key in the console to cycle through previous commands.
getting help for R functions (different methods?)
You can type the function name in the Help tab search box.
In the console, you can use the help() function or a question mark ? followed by the function name (e.g., ?print)