R Basic Flashcards
Learn basics of R
What does IDE stand for?
Interactive Development Environment
FUNCTION: install a package in R
install.packages (“packagename”)
FUNCTION: load and attach an R Package to a session
Library (packagename)
FUNCTION: List of objects
ls()
FUNCTION: square root
sqrt
FUNCTION: find the object data type
class(object)
What is a data frame?
a table
FUNCTION: load a data set
data(“data set name”)
What is the $ called?
the accessor
What is an accessor?
a function that allows a user to interact with slots of an object
== is what
logical operator, will be true or false
what is data type “factor”?
categorical data
FUNCTION: levels()
returns categories/options from a “factor data” type object
FUNCTION: names()
designed to extract the column names from a data frame
Can also be used to assign names to numeric values
ie.
cost
R name for “data type”
class
FUNCTION: table()
takes a vector as input and returns the frequency of each unique element in the vector
> x table(x)
x
a b c
2 3 1
FUNCTION: to concatenate
c()
ie. c(a,b,c)
c(a=1,b=2,c=3)
FUNCTION: to access a subset/column of a vector
VectorName[2]
##the 2 is for the second column
VectorName[c(1,3)]
VectorName[“columnname”,”columnname2”]
When creating a vector, what indicates that a element is a string, not a variable?
Double quotes around the element (for strings)
What is coercion?
An attempt by R to be flexible with data types
FUNCTION: to convert variable/object to character types
as.character()
FUNCTION: to convert variable/object to number types
as.numeric()
What does NA mean?
Number missing
Can be created by R trying to coerce data
FUNCTION: to specify a length
length. out=5
ie. seq(0, 100, length.out = 5)