Back

R Blog

Chocolate Flavors 1/18/22 @tidytuesday

This week's Tidy Tuesday data is a record of chocolate ratings. I created a simple Shiny App that provides a text description of chocolates in a certain cocoa percentage range. For instance:

Chocolates with cocoa percentage ranging from 85% to 100% are most often described as: bitter, spicy, earthy, intense, and mild-bitter. They most often originate from: Blended Origins, Ecuador, and Belize.

https://g-econ.shinyapps.io/chocolate/

Flight of the Bumblebees 1/10/22 @tidytuesday

Tidy Tuesday is a weekly data science “challenge” for the R community. This week's dataset tracks bee colonies in the US over the past few years.

This week, I made an R Shiny web app that converts data on the number of colonies in each state into a song. My favorite state is listen to is Georgia (my home state). When played fast enough, these little songs sound vaguely like Flight of the Bumblebee.

The app can be found here.

At the moment it does not work on iphone, but has been tested on windows, linux, and android.

Code Golf Abundant Numbers 11/15/21 @codegolf

The goal in code golf is to produce a program that solves a problem with as few characters as possible. Here is a code golf problem where R does pretty well.

Abundant Numbers

This problem comes from Here.

An abundant number is a number for which the sum of its proper divisors (divisors not including the number itself) is greater than the number itself. For example **12* is abundant because its proper divisors are 1, 2, 3, 4, and 6 which add up to 16.*

Print all the abundant numbers from **1* to 200 inclusive, each on their own line.*

Code: (46 Characters)

This code takes advantage of R's matrix functions and operators.

a=1:200
t(t(a[((!outer(a,a,"%%"))%*%a)>=2*a]))
##       [,1]
##  [1,]    6
##  [2,]   12
##  [3,]   18
##  [4,]   20
##  [5,]   24
##  [6,]   28
##  [7,]   30
##  [8,]   36
##  [9,]   40
## [10,]   42
## [11,]   48
## [12,]   54
## [13,]   56
## [14,]   60
## [15,]   66
## [16,]   70
## [17,]   72
## [18,]   78
## [19,]   80
## [20,]   84
## [21,]   88
## [22,]   90
## [23,]   96
## [24,]  100
## [25,]  102
## [26,]  104
## [27,]  108
## [28,]  112
## [29,]  114
## [30,]  120
## [31,]  126
## [32,]  132
## [33,]  138
## [34,]  140
## [35,]  144
## [36,]  150
## [37,]  156
## [38,]  160
## [39,]  162
## [40,]  168
## [41,]  174
## [42,]  176
## [43,]  180
## [44,]  186
## [45,]  192
## [46,]  196
## [47,]  198
## [48,]  200