This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, ...) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frame.match #### | |
frame.match <- function(data.1, data.2, id.col, ...) { | |
# User defined for comparing dataframe cells | |
require(dplyr) | |
results <- list() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Useful libraries #### | |
library(readxl) # excel | |
library(plyr) # Tidy data | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) # Plot data | |
library(RColorBrewer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plotData <- function(data, ...){ | |
library(ggplot2) | |
library(viridis) | |
library(ggthemes) | |
library(ggalt) | |
for (i in seq_along(data)) { | |
tryCatch({ |
NewerOlder