Parameterizing Reports with Whisker!
Copying and pasting similar reports over and over is inefficient and can lead to coding error. We can use the whisker package to semi-automate this!
Copying and pasting similar reports over and over is inefficient and can lead to coding error. We can use the whisker package to semi-automate this!
A website I created to help early R users understand the basics of R programming while providing ample opportunity for ‘real world’ practice problems with interesting, sometimes messy, data.
Grid is the very first CSS module created specifically to solve the layout problems we’ve all been hacking our way around for as long as we’ve been making websites.
Grid is the very first CSS module created specifically to solve the layout problems we’ve all been hacking our way around for as long as we’ve been making websites.
Grid is the very first CSS module created specifically to solve the layout problems we’ve all been hacking our way around for as long as we’ve been making websites.
Welcome to The University of Washington and your crash course on R. Note that this class will not be incredibly robust (we have three days) but it will aim to provide you the tools necessary to do well in your stats classes and beyond. Futher, I believe several of you will take a semester long course in R. You’ll be ahead of that game but will go into more depth during that class.
In the previous lesson we covered the very basics of R. We discussed that R can be a fancy calculator, interpret logical arguments, and some fun facts sprinkled throughout. In addition, we covered basic data types and structures. Alone, this is good information to know… and is indeed the very bare bones introduction… but we are here to look at data - to manipulate data in a meaningful way. The first step towards data exploration is learning how to find values in a data set.
Some of the most common data-related issues for those new to healthcare research (probably any research) revolve around string and date manipulation. Fortunately for us, R has some really incredible packages to help us deal with them. Like anything in R, it can be done in base R. Though, you’ll never use base R again for string/date manipulation so… i’m not going to cover it here. Again, this is meant to be a broad overview of both of the packages so that you can go back to them when you’re stuck!
For this lesson, we’re going to use the gapminder data, which can be found in its original form here. If you’re reading this and not attending the class, I would highly encourage you to check out the website! The late Hans Rosling was a brilliant guy and his work, followed up by children, is worth digging through. The main purpose of this exercise is to learn how to graph your data; however, we first need to understand the (subjectively) best format for data, tidy data.
Now that you’ve mastered the basics of R, and data manipulation with dplyr, you’re ready for an introduction to functions and loops. Hopefully, the time you’ll need for loops is minimal since dplyer has solved some grouping issues for us. But, you should still learn them just in case (and so you can understand them when reading others’ code). Here I want to cover: Functions and if statements Loops Functions and if statements Functions are a key part of R.
Basic Math and Logic with R # —- SETUP x <- 18 r_is_cool <- 23 # 1 x + r_is_cool #2 x >= r_is_cool #3 x < r_is_cool & x + 10 > r_is_cool #4 sum(c(TRUE, TRUE, FALSE, TRUE)) Indexing Vectors # —- SETUP what_the_vec <- c(seq.int(from = 8, to = 72, by = 2)) # 1 what_the_vec[14] # 2 new_vec <- what_the_vec[c(2, 8, 20)] # 3 new_vec[2] < new_vec[1] # 4 new_vec2 <- new_vec[-1] Indexing Data Frames Section 1 # 1 dim(iris) # — OR —- str(iris) # str gives more info.
For problem set two, we will be building on modules 0 - 3 and testing your skills of tidyverse, dates, strings, and plotting. So, if you are unfamiliar with those, take a look at the modules and come back. The entirety of this problem set will build off of the COVID Apple Mobility data. This data shows the percent of daily direction requests sent to the Apple servers for thousands of local regions by different types of transportation (walking, biking, and driving).
This problem set will require knowledge of both Lesson 1 and Lesson 2. If you haven’t read over those, go ahead and do that then come back. Or, if you think you got it, carry on! Basic Math and Logic with R Store the value 18 in a variable x and the value 23 in the varialbe r_is_cool. Write an simple expression in your console that adds those two variables Write an expression to test whether or not x is greater than or equal to r_is_cool Write an expression to test whether x is less than r_is_cool AND x + 10 is greater than r_is_cool What is the sum of the following vector: c(TRUE, TRUE, FALSE, TRUE)?
Function Concepts Answer 1: The general structure of a function if function(~arguments~){do something to arguments}. Of course, that is an informal definition so anything resembling that counts! Answer 2: Neither the second or third option will run. Answer 3: The two mentioned produce errors because there is no specified y value. The x value is pre-specified and so as long as we tell R what the y value should be, it will use the default x.
Initial Setup # load relevant libraries library(tidyverse) library(lubridate) # read in data (this step looks slightly different for me) mobility <- read.csv("../../data/applemobilitytrends.csv") # view the structure str(mobility) Question 1 # Since we are tidyverse experts, we can answer all these questions in one try: mobility_CLT <- mobility %>% # step 1 filter(region == "Charlotte", sub.
This problem set will be the last of them. It will build on the 4th module. So, if you’ve not checked it out, go ahead and do that! We will be building on a lot of components from the other modules as well. Function Concepts Here, I just want to touch on the general concepts of functions. What is the general structure of a function? Consider this function: my_function <- function(x = 2, y){ x + 2*y}.
If given a lump sum of cash (lottery, inheritance, bonus), what is the best way to invest it? Read on to find out!
In healthcare economics, the most option most likely to be cost-effective may not be the best choice! Read on to find out why that may be.
Other R packages built around assessing medication adherence can be computationally inefficient and difficult to use due to overburdened functions. The goal of adheRenceRX was to create adopt the tidy framework with a C+ backend to enhance the adherence assessment experience!