\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{enigmo} \pdfinfo{ /Title (basics-in-r.pdf) /Creator (Cheatography) /Author (enigmo) /Subject (Basics in R Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{09AAAE} \definecolor{LightBackground}{HTML}{EFF9F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Basics in R Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{enigmo} via \textcolor{DarkBackground}{\uline{cheatography.com/35921/cs/11301/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}enigmo \\ \uline{cheatography.com/enigmo} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 1st April, 2017.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{4.8356 cm} x{12.4344 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{R als Taschenrechner}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{1 + 2}} & Addiert die Zahlen \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{6 * 9}} & Multipliziert die Zahlen \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{85 / 17}} & Dividiert die Zahlen \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} {\bf{2 \textasciicircum{} 10}} & Berechnet die zehnte Potenz von 2 \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{sqrt(225)}} & Berechnet die Wurzel aus 225 \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.454 cm} x{13.816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Variablen in R}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{x \textless{}- 3}} & Weist der Variable {\bf{x}} die Zahl 3 zu \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{x = 3}} & Alternative Zuweisung von Variablen \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{x + y}} & Addiert die Variablen {\bf{x}} und {\bf{y}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{y / x}} & Dividiert die Variable {\bf{y}} durch {\bf{x}} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{y * x}} & Multipliziert die Variablen {\bf{x}} und {\bf{y}} \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.0445 cm} x{11.2255 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Mit Vektoren rechnen in R}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{c(2, 7, 5, 9)}} & Erstellt einen Vektor und wirft den Inhalt in der Konsole aus \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{v \textless{}- c(2, 7, 5, 9)}} & Weist der Variable {\bf{v}} den Vektor zu \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{v}} & Wirft den Inhalt der Variable {\bf{v}} in der Konsole aus \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} {\bf{v / 2}} & Teilt alle Werte in Variable {\bf{v}} durch 2 \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{v - w}} & Subtrahiert die Werte in {\bf{w}}* von den Werten in {\bf{v}} \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} {\bf{v * w}} & Multipliziert die Werte in {\bf{v}} mit den Werten in {\bf{w}} \tn % Row Count 16 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.3537 cm} x{11.9163 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Dezimalzahlen und Strings}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{4.7}} & Dezimalzeichen: "{\bf{.}}" \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{"qwertz"}} & Erstellen von Strings mit Anführungszeichen \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{q \textless{}- "Goodbye"}} & Zuweisen von Strings \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} {\bf{paste(q, w)}} & Verketten von Vektoren \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{paste0(q, w)}} & Verketten von Vektoren ohne Lücken \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.0445 cm} x{11.2255 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Datenanalyse mit dplyr}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{install.packages()}} & Pakete installieren - Paketname muss in Anführungszeichen \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{library()}} & L{\"a}dt ein installiertes Paket \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{::}} & Nimmt Funktion aus spezifiziertem Paket, z.B. {\bf{dplyr::summarise}} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} {\bf{\textgreater{}\%\textgreater{}}} & magrittr Pipe-Operator, verbindet Funktionen \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{group\_by()}} & dplyr-Funktion, gruppiert Datensatz nach einer Spalte \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} {\bf{filter()}} & dplyr-Funktion, filtert Datensatz nach einer Spalte \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{summarise()}} & dplyr-Funktion, fasst Ergebnisse zB durch Summierung zusammen \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} {\bf{mutate()}} & dplyr-Funktion, fügt eine neue Spalte hinzu \tn % Row Count 20 (+ 2) % Row 8 \SetRowColor{LightBackground} {\bf{arrange()}} & dplyr-Funktion, sortiert Ergebnisse zB der Gr{\"o}{\ss}e nach \tn % Row Count 23 (+ 3) % Row 9 \SetRowColor{white} {\bf{split()}} & dplyr-Funktion, schneidet Ergebnis an einer bestimmten Stelle ab \tn % Row Count 26 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.908 cm} x{10.362 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Datenstrukturen in R}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{seq(11, 91, 10)}} & Erzeugt eine Zahlenfolge nach bestimmten Kriterien \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{x \textless{}- c(seq(11 ,91, 10))}} & Weist {\bf{x}} einen Vektor mit der Sequenz zu \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{matrix(c(x, z), 9, 2)}} & Erzeugt aus {\bf{x}} und {\bf{z}} eine Matrix mit 9 Zeilen und 2 Spalten \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} {\bf{data.frame(x, y, z)}} & Erzeugt aus {\bf{x}}, {\bf{y}} und {\bf{z}} einen Dataframe \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.181 cm} x{12.089 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Logische Operatoren und Indizes}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{\%in\%}} & Bsp.: 3 \%in\% c(1,2,3) ist TRUE \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{\$}} & Zugriff über Spaltennamen, Bsp.: data\$namen \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{data{[}i,j{]}}} & Indizierung - {\bf{i}}-te Zeile, {\bf{j}}-te Spalte \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{|}} & "oder" \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} {\bf{\&}} & "und" \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} {\bf{==}} und {\bf{\&\&}} & "ist gleich" - logischer Operator, ob links gleich rechts ist \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.3537 cm} x{11.9163 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Datenimport und Datenexport}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{getwd()}} & Zeigt das aktuelle working directory \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{setwd()}} & Setzt das working directory \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{read.csv()}} & Importiert eine CSV-Datei \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} {\bf{?read.csv}} & Öffnet die Hilfeseite von {\bf{read.csv}} in RStudio \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{View()}} & Zeigt den Dataframe als Tabelle an \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} {\bf{head()}} & Zeigt die ersten x Eintr{\"a}ge eines Dataframes (unsortiert) \tn % Row Count 12 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{tail()}} & Zeigt die letzten x Eintr{\"a}ge eines Dataframes (unsortiert) \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} {\bf{nrow()}} & Zeigt die Anzahl der Zeilen eines Dataframes an \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} {\bf{ncol()}} & Zeigt die Anzahl der Spalten eines Dataframes an \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} {\bf{length()}} & Zeigt die Anzahl Eintr{\"a}ge an, z.B. eines Vektors \tn % Row Count 21 (+ 2) % Row 10 \SetRowColor{LightBackground} {\bf{class()}} & Zeigt die Klasse eines Objekts an, z.B. "data.frame" \tn % Row Count 23 (+ 2) % Row 11 \SetRowColor{white} {\bf{str()}} & Zeigt Struktur eines Objekts an, z.B. "data.frame" + die Struktur der Spalten, z.B. "numeric" \tn % Row Count 27 (+ 4) % Row 12 \SetRowColor{LightBackground} {\bf{is.na()}} & Logical Operator für fehlende Werte in einem Datenobjekt \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.3537 cm} x{11.9163 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Datenimport und Datenexport (cont)}} \tn % Row 13 \SetRowColor{LightBackground} {\bf{any()}} & Erfüllt irgendein Wert im Objekt eine bestimmte Bedingung? Bsp.: {\bf{any(is.na())}} \tn % Row Count 4 (+ 4) % Row 14 \SetRowColor{white} {\bf{unique()}} & Filtert alle Duplikate heraus \tn % Row Count 6 (+ 2) % Row 15 \SetRowColor{LightBackground} {\bf{duplicated()}} & Logical Operator für "Bist du ein Duplikat?" \tn % Row Count 8 (+ 2) % Row 16 \SetRowColor{white} {\bf{na.omit()}} & Zeigt ein Objekt ohne fehlende Werte an \tn % Row Count 10 (+ 2) % Row 17 \SetRowColor{LightBackground} {\bf{sum() }} & Berechnet die Summe von Werten \tn % Row Count 12 (+ 2) % Row 18 \SetRowColor{white} {\bf{max()}} & Zeigt den gr{\"o}{\ss}ten Werte in einem Objekt an \tn % Row Count 14 (+ 2) % Row 19 \SetRowColor{LightBackground} {\bf{min()}} & Zeigt den kleinsten Wert in einem Objekt an \tn % Row Count 16 (+ 2) % Row 20 \SetRowColor{white} {\bf{mean()}} & Zeigt den Mittelwert eines Objekts an \tn % Row Count 18 (+ 2) % Row 21 \SetRowColor{LightBackground} {\bf{table()}} & Zeigt die H{\"a}ufigkeitstabelle eines Objekts an \tn % Row Count 20 (+ 2) % Row 22 \SetRowColor{white} {\bf{sort()}} & Sortiert die Eintr{\"a}ge eines Objekts \tn % Row Count 22 (+ 2) % Row 23 \SetRowColor{LightBackground} {\bf{as.character()}} & Setzt die Klasse eines Objekts auf "character" \tn % Row Count 24 (+ 2) % Row 24 \SetRowColor{white} {\bf{as.factor()}} & Setzt die Klasse eines Objekts auf "factor" \tn % Row Count 26 (+ 2) % Row 25 \SetRowColor{LightBackground} {\bf{as.numeric()}} & Setzt die Klasse eines Objekts auf "numeric" \tn % Row Count 28 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}