RStudio functions: Flashcards
A + B + Enter button
Answer for A + B
*
Multiply
/
Divide
To the power of
Brackets
To separate different functions used in one
A ← 3
Store the value 3 in variable A
What is a scalar variable?
A variable storing a single value
Variable (eg. A) + Enter
Displays value stored in variable
C ← “apples”
Stores the word apples in variable C
What are vectors?
Variables that can hold more than one value
D ← c(3, 7, 1)
Stores vector 3, 7, 1 in variable D
C stands for combine
D[2]
Allows access to the second value stored in the vector variable D
What are data frames?
A store of large amounts of data
Putting name of data frame
Displays the full set of data in data frame
Cars$Mpg
Codes for only mpg column in the cars data frame
DateFrameName[RowNumber, ColumnNumber]
Helps distinguish between rows and columns in a table
Cars[ , 1]
When row number is left blank, it will return all the rows.
In this example, the first column of rows of car will be returned
What is a function?
Anything that performs a particular operation on our data
What is the format that all functions follow on R Studio?
Function_name(argument)
What is an argument?
The input for the function
What would the function “ mean(e) “ do?
Give the mean/average of values in vector e
What code would you use to calculate the mean mpg of cars?
Mean(cars$mpg)
How do you find the column names in a data frame?
By printing the whole data frame
Names(name of data frame )
Only shows the column names of a data frame
Head(data frame name )
Only shows column names and top few rows of data frame
Why might the function “ head(name of data frame)” function cause the full data frame to be shown?
The function shows the first 10 rows, so if data frame has 10 or less rows then all of it will be shown
How are arguments separated in all functions?
Using commas
How do you define how many rows you want from a data frame?
head(name of date frame, n= )
Hist()
Creates a histogram
Draw histogram of horsepower (hp) from cars:
hist(cars$hp)
What is the standard layout of data?
- Each column represents a different variable
- Each row represents a different subject or replicate
How is the standard layout of data different from the layout used by people when making spreadsheets?
Each condition is put into separate columns
What is an advantage of the standard layout of data?
It is much easier to record additional variables in a data frame
What is the advantage of using histograms over box plots?
Histograms show more information
What is the advantage of using boxplots over histograms?
It is easier to compare data presented as a box plot than as a histogram