Skip to content

Instantly share code, notes, and snippets.

# Table 1
# A basic, descriptive table that you would usually see as Table 1 in a
# publication
plotDf <-read_csv(urlfile)
# Tests if multiple groups (data$arm)
tests.1 <- function(data, ...) {
# Apply functions ####
# There are cases where you want to "do something" to each element in a given
# data structure. For example, we might want to calcuate the
# mean for each variable (column) in a dataframe.
# Looping is a common way to do this.
# Data
urlfile <-"https://raw.githubusercontent.com/dantalus/intro_workshop/master/plot.csv"
plotDf <-read.csv(urlfile)
# install.packages(c("ggthemes", "ggbeeswarm"))
library(ggthemes)
library(ggbeeswarm)
library(ggplot2)
library(dplyr)
install.packages("tidyverse")
library(tidyverse)
# Objects ####
# Most of R, from an applied point of view anyway, is the process of creating
# objects and feeding them into functions to make amazing, new objects.
# amazing_new_object <- f(object)
# Table 1
# A basic, descriptive table that you would usually see as Table 1 in a
# publication
# Tests if multiple groups (data$arm)
tests.1 <- function(data, ...) {
tests.list <- list()
# Most of R, from an applied point of view anyway, is the process of creating objects and feeding them into functions to make amazing,
# new objects.
# amazing_new_object <- f(object)
x <- c(3, 4, 5)
y <- mean(x)
# This is true in the big picture sense as well
# information
# frame.match ####
frame.match <- function(data.1, data.2, id.col, ...) {
# User defined for comparing dataframe cells
require(dplyr)
results <- list()
# Returns a correlation coefficient, rounded, with any trailing zeros printed
corr <- function(x, y, ...){
as.numeric(formatC(round(cor(x = x, y = y,
use = "pairwise.complete.obs"), 2),
format = "f", 2))
}
# Generate the matrix of correlation coefficients. In this example, I want to
# correlate a set of variables (A:F) with one other variable (G), rather than
# Useful libraries ####
library(readxl) # excel
library(plyr) # Tidy data
library(dplyr)
library(tidyr)
library(ggplot2) # Plot data
library(RColorBrewer)
plotData <- function(data, ...){
library(ggplot2)
library(viridis)
library(ggthemes)
library(ggalt)
for (i in seq_along(data)) {
tryCatch({