Notes on Programming or Whatever

R, sports, and maybe cooking

Kruskal-Wallis Test

on August 10, 2022

I want to mentally prepare for the upcoming semester. Today, let me do a warm-up exercise of computing a Kruskal-Wallis test. library("palmerpenguins") library("tidyverse") You can see that I will use the ubiquitous Palmer Penguins data set str(penguins) ## tibble [344 × 8] (S3: tbl_df/tbl/data.frame) ## $ species : Factor w/ 3 levels "Adelie","Chinstrap",..: 1 1 1 1 1 1 1 1 1 1 ... ## $ island : Factor w/ 3 levels "Biscoe","Dream",.

Continue reading

Deck of Cards

on August 8, 2022

Years ago, I had to simulate a deck of playing cards in a Python course. Oddly enough, I don’t recall ever carrying out this task in R. Today, I saw a neat code snippet about the crossing() command in tidyr by Tan Ho in the R4DS Slack channel, so let us give it a try. library("tidyverse") suit <- c("D", "H", "C", "S") rank <- c(2:10, "J", "Q", "K", "A") deck <- tidyr::crossing(rank, suit) |> dplyr::mutate(card = paste0(rank, suit)) This yields a data frame with 3 columns: rank, suit, card.

Continue reading

Return to Mermaid Diagrams

on July 17, 2022

I have been meaning to get back into making flow charts for a while. Over the years, I have tried different code packages, but I think that mermaid graphs make the most sense for my simple goals. library("DiagrammeR") For today’s practice, let us try to make a 2-by-2 decision tree. DiagrammeR::mermaid(" graph LR node1(start) node2{A} node3{not A} node4[B given A] node5[not B given A] node6[B given not A] node7[not B given not A] node1 --> node2 node1 --> node3 node2 --> node4 node2 --> node5 node3 --> node6 node3 --> node7 ") {"

Continue reading

Stardew Valley Expanded

on July 17, 2022

Now that I finally have some free time, I want to play the Stardew Valley Expanded mod. But first, let us make a flow chart of the mods and their dependencies. library("DiagrammeR") my_plot <- DiagrammeR::mermaid(" graph LR SMAPI[SMAPI] Content_Patcher[Content Patcher] Custom_NPC_Exclusions[Custom NPC Exclusions] Expanded_Preconditions_Utility[Expanded Preconditions Utility] Extra_Map_Layers[Extra Map Layers] Farm_Type_Manager[Farm Type Manager] JSON_Assets[JSON Assets] SAAT[SAAT] Shop_Tile_Framework[Shop Tile Framework] Spacecore[Spacecore] Stardew_Valley_Expanded{Stardew Valley Expanded} SMAPI --> Content_Patcher SMAPI --> Custom_NPC_Exclusions SMAPI --> Expanded_Preconditions_Utility SMAPI --> Extra_Map_Layers SMAPI --> Farm_Type_Manager SMAPI --> JSON_Assets SMAPI --> Shop_Tile_Framework SMAPI --> Spacecore Content_Patcher --> Farm_Type_Manager Expanded_Preconditions_Utility --> JSON_Assets Expanded_Preconditions_Utility --> Shop_Tile_Framework Spacecore --> JSON_Assets SMAPI --> Stardew_Valley_Expanded Content_Patcher --> Stardew_Valley_Expanded Custom_NPC_Exclusions --> Stardew_Valley_Expanded Expanded_Preconditions_Utility --> Stardew_Valley_Expanded Extra_Map_Layers --> Stardew_Valley_Expanded Farm_Type_Manager --> Stardew_Valley_Expanded JSON_Assets --> Stardew_Valley_Expanded SAAT --> Stardew_Valley_Expanded Shop_Tile_Framework --> Stardew_Valley_Expanded Spacecore --> Stardew_Valley_Expanded ")

Continue reading