A blog of thoughts

Formatting Currencies in R

Here are a few different ways to format numbers in R. A few of theme can be accomplished using the paste function in R. I’ve found that there are a few different methods to do this. Using the scales package Using the scales packages from Hadley, there is a great function with various options including passing a vector. library(scales) dollar_format()(c(-100, 0.23, 1.456565, 2e3)) ## [1] "-$100.00" "$0.23" "$1.46" "$2,000.

How to bend the data

One of the fundamental priorities of a data scientist is being able to bend the data into a format that is plyable. Being able to effectively use tidyr, reshape2 and the core functions are key to success in being able to manage a large dataset without swimming or drowning in it. But it does take discipline and instinct to understand the validity of the data so lets exercise this a little:

Phillips Hue in R

The following function can be used to find and display the internal IP address needed to retrieve the IP address from Hue Bridge. You will need to generate an API key i.e. a “userkey” as I called it below. getIP <- function() { url <- paste0("https://www.meethue.com/api/nupnp") res <- httpGET(url) resJson <- fromJSON(res) res <- resJson[["internalipaddress"]] res } In order to know what light you should change the state on, one can run the following to retrieve the available lights connected on the network.

Simulate Doctor Visit Resource Planning Using Simmer

Here I’ve tried to come up with a simple layout on how we might simulate doctor’s visits. Following code tries to resource plan certain doctor visits based on the vignette that was provided with the simmer package. library(simmer) ## Warning: package 'simmer' was built under R version 3.6.2 set.seed(42) env <- simmer("SuperDuperSim") env ## simmer environment: SuperDuperSim | now: 0 | next: ## { Monitor: in memory } patient <- trajectory("patients' path") %>% ## add an intake activity seize("nurse", 1) %>% timeout(function() rnorm(1, 15)) %>% release("nurse", 1) %>% ## add a consultation activity seize("doctor", 1) %>% timeout(function() rnorm(1, 20)) %>% release("doctor", 1) %>% ## add a planning activity seize("administration", 1) %>% timeout(function() rnorm(1, 5)) %>% release("administration", 1) env %>% add_resource("nurse", 1) %>% add_resource("doctor", 2) %>% add_resource("administration", 1) %>% add_generator("patient", patient, function() rnorm(1, 10, 2)) ## simmer environment: SuperDuperSim | now: 0 | next: 0 ## { Monitor: in memory } ## { Resource: nurse | monitored: TRUE | server status: 0(1) | queue status: 0(Inf) } ## { Resource: doctor | monitored: TRUE | server status: 0(2) | queue status: 0(Inf) } ## { Resource: administration | monitored: TRUE | server status: 0(1) | queue status: 0(Inf) } ## { Source: patient | monitored: 1 | n_generated: 0 } env %>% run(80) %>% now() ## [1] 80 env %>% peek(3) ## [1] 80.

Time and Difficulty

Sometimes, seeing data in a 3 dimensional space gives us better visibility to the rest of the world. You will see that we have taken a hypothetical experiment and tried to rate different ideas by their complexity and likelihood to succeed. #Libraries to import library(tidyverse) ## Warning: package 'tibble' was built under R version 3.6.2 ## Warning: package 'purrr' was built under R version 3.

Minature Generative Art

Sometimes something simple can turn out to generate the most beautiful things. Following you will find a few lines of code that present a beautiful pattern. Oval Curve n <- 300 t1 <- 1:n t0 <- seq(3,2*n+1,2) %% n t2 <- t0 + (t0 == 0)*n df <- data.frame(x = cos((t1-1)*2*pi/n), y = sin((t1-1)*2*pi/n), x2 = cos((t2-1)*2*pi/n), y2 = sin((t2-1)*2*pi/n)) ggplot(df,aes(x,y,xend = x2,yend = y2)) + geom_segment(alpha = .

Extracting Hyperlinks from an XSLX in R

In Progress install.packages(“keras”) library(keras) devtools::install_github(“omarwagih/ggseqlogo”) devtools::install_github(“leonjessen/PepTools”)

Human Ingenuity and Speed

library(tidyverse) ## ── Attaching packages ─────────────────────────────── tidyverse 1.3.0 ── ## ✓ ggplot2 3.3.0 ✓ purrr 0.3.4 ## ✓ tibble 3.0.1 ✓ dplyr 0.8.5 ## ✓ tidyr 1.0.2 ✓ stringr 1.4.0 ## ✓ readr 1.3.1 ✓ forcats 0.5.0 ## Warning: package 'tibble' was built under R version 3.6.2 ## Warning: package 'purrr' was built under R version 3.6.2 ## ── Conflicts ────────────────────────────────── tidyverse_conflicts() ── ## x dplyr::filter() masks stats::filter() ## x dplyr::lag() masks stats::lag() Data Building The first thing we need to understand is where we have come and where we are going.

Words With Friends Musings

#library(tidyverse) # IMport Data #filepath <- "~/Dropbox/Word Lists/WordsWithFriends/enable1-wwf-v4.0-wordlist.txt" #wwfList <- read_csv(filepath, col_names = FALSE) #wwfList %>% stringr::str('.ae.')

Page 1 of 3