I forget how to do so many things in programming. I mainly use R now, so this is my elephants grave yard of forgotten code that I need to remember for later.

dplyr

dplyr cheatsheet

library(dplyr)

select

select for picking specific columns

all_data   <- mtcars

smaller_df <- all_data %>%
                select(mpg,cyl)

Summarize data

summarise(all_data, mean=mean(mpg),
                    sd=sd(mpg))

Group by

summary_df <- all_data %>% 
              group_by(cyl,am) %>%
              summarize(mean=mean(mpg),
                        se=sd(mpg)/sqrt(length(mpg)))

Filter rows

restricted_df <- all_data %>% 
                 filter(gear > 3)

restricted_df <- all_data %>% 
                 filter(gear > 3,
                        am == 1)

Mutate

Add columns, delete columns

dim(all_data)

all_data <- all_data %>% 
            mutate(newCol = rep(0,32))

all_data <- all_data %>% `[<-`("mpg",value=NULL)

Arrange order

arrange(mtcars, mpg)  # ascending (small to large)

arrange(mtcars, desc(mpg)) # descending (large to small)

Papaja

For apa style papers

Figures

  1. jou mode doesn’t respect fig.width or fig.height, use out.width=“3in” for single column
  2. use out.width=“\textwidth” and fig.env="figure*" to span both columns

Indentation in jou mode

for yaml

header-includes:
   - \setlength\parindent{24pt}

colons in yaml

Use the code &#58; for colons

add latex to header for journal name

add to yaml

header-includes:
  - \journal{Journal of Foobar}

kableextra

For the grammar of tables…Makes awesome tables with ease!

http://haozhu233.github.io/kableExtra/awesome_table_in_html.html#overview