Cheat sheet of functions used in the lessons
length() # how many elements are in a particular vectorclass() # the class (the type of element) of an objectstr() # an overview of the object and the elements it containsc() # create vector; add elements to vector [ ] # extract and subset vector%in% # to test if a value is found in a vectoris.na() # test if there are missing valuesna.omit() # Returns the object with incomplete cases removedcomplete.cases()# elements which are complete casesdownload.file() # download files from the internet to your computerread.csv() # load CSV file into R memoryhead() # check the top (the first 6 lines) of an object including data framesfactor() # create factorslevels() # check levels of a factornlevels() # check number of levels of a factoras.numeric(levels(x))[x] # convert factors where the levels appear as numbers to a numeric vectordata.frame() # create a data framedim() # check dimension of data framenrow() # returns the number of rowsncol() # returns the number of columnshead() # shows the first 6 rowstail() # shows the last 6 rowsnames() # returns the column names (synonym of colnames() for data frame objects)rownames() # returns the row namesstr() # check structure of the object and information about the class, length and content of each columnsummary() # summary statistics for each columnseq() # generates a sequence of numbersinstall.packages() # install a CRAN package in Rlibrary() # load installed package into the current sessionselect() # select columns of a data framefilter() # allows you to select a subset of rows in a data frame%>% # pipes to select and filter at the same timemutate() # create new columns based on the values in existing columnsgroup_by() # split the data into groups, apply some analysis to each group, and then combine the results.summarize() # collapses each group into a single-row summary of that grouptally() # counts the total number of records for each category.write.csv() # save CSV fileggplot2(data= , aes(x= , y= )) + geom_point( ) + facet_wrap () +
theme_bw() + theme() aes() # by selecting the variables to be plotted and the variables to
define the presentation such as plotting size, shape color, etc.geom_ # graphical representation of the data in the plot (points, lines, bars). To add a geom to the plot use + operatorfacet_wrap() # allows to split one plot into multiple plots based on a factor included in the datasettheme_bw() # set the background to whitetheme() # used to locally modify one or more theme elements in a specific ggplot object
*
src_sqlite # connect dplyr to a SQLite database filetbl # connect to a table within a databasecollect # retrieve all the results from the databaseexplain # show the SQL translation of a dplyr queryinner_join # perform an inner join between two tablescopy_to # copy a data frame as a table into a database