R cheat sheet - GitHub Pages
R cheat sheet
By @MaryJoWebster March 2019 Data frame ? This is from Base R; this is used for storing data tables. Tidyverse makes a "tibble" which is supposed to be a slightly better version of a data frame.
% This is a pipe operator used in Tidyverse to connect actions. (Cmd+Shift+M on a Mac)
See the Tools menu in RStudio and look at Keyboard Shortcuts (the key strokes are different for Windows and Mac)
df$columnname --- You might see this syntax occasionally. This is how to be explicit about exactly which dataframe a column is coming from. It's the name of the data frame with a dollar sign and then followed by the name of the column.
Stringr::sub_str() -- you might see syntax like this. This is how to be explicit about which package a function is coming from. In this case it's the "stringr" package and sub_str is the name of a function from that package. getwd() --how to find out what your working directory is. You can type this in any file (script, markdown, etc) or in the console.
Dplyr basic syntax: Select(columnname, columname)
Filter(columname== `value')
Group_by(columnname)
Summarize( newcolumnname = n() ) --- this will count the records Summarize( newcolumnname = sum(columnname) ) -- this will sum the values in a column
Summarize( newcolumnname = mean(columnname) ) -- this will average values in a column
Arrange(columnname) -- this will sort your results by column specified, ascending
Arrange(desc(columnname) ? this will sort descending
Mutate( newcolumnname = .......) ) -- this is how you add a new column
How to calculate a percent when grouping data: Df %>% group_by(statename) %>% summarize(count = n() ) %>% mutate(pct = count/sum(count) #note- the mutate line is grabbing the "count" field created in the summarize line and dividing it by the sum of all the values in "count"
How to add a new column to a data frame using mutate. For this example, let's assume we have two columns we want to add together to create a "total" column.
df % mutate(total = column1 + column2)
Importing using Tidyverse: Readr package in Tidyverse comes with 5 "parsers" for importing different text file types. (Note that BaseR has a function called "read.csv" that functions very differently) read_csv() ? for comma-delimited files read_tsv() ? for tab-delimited files read_fwf() ? for fixed-width files read_log() for web log files If you need to import an Excel file, you need the readxl package from Tidyverse (see below) Syntax for read_csv. Make sure your data file is in your working directory. Df ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- r cheat sheet github pages
- html table width
- angular4 restful aula prof edson belém
- using style elements in the report and tabulate sas
- shiny cheat sheet
- ng table column width
- faqs about the package in r
- package dt
- a short list of the most useful r commands
- table layout in css css table rendering in detail by eric
Related searches
- cheat sheet for word brain game
- macro cheat sheet pdf
- logarithm cheat sheet pdf
- excel formula cheat sheet pdf
- excel formulas cheat sheet pdf
- excel cheat sheet 2016 pdf
- vba programming cheat sheet pdf
- macro cheat sheet food
- free excel cheat sheet download
- onenote cheat sheet pdf
- punctuation rules cheat sheet pdf
- excel formula cheat sheet printable