This file contains hidden or 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
| #### 8-QUEENS TIDYVERSE SOLVE #### | |
| library(tidyverse) | |
| ## number of queens (and size of boards) | |
| n <- 8 | |
| ## if we brute-foced this from the start we would be searching | |
| choose(n^2, n) # n=8: 4426165368 | |
| ## solutions which is just too many. We can simplify this by |
This file contains hidden or 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
| ## A data.frame can contain a complex structure | |
| ## under certain conditions. | |
| ## create a normal matrix but give it a new class | |
| set.seed(1) | |
| mymat <- structure( | |
| matrix(sample(1:5, 40, replace = TRUE), 10, 4), | |
| class = "actually_a_matrix" | |
| ) | |
| mymat |
This file contains hidden or 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
| gistr |
This file contains hidden or 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
| gistr |
This file contains hidden or 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
| x <- letters | |
| numbers <- runif(8) | |
| numbers | |
| [1] 0.3229318 0.5933054 0.7778408 0.3898947 0.1309717 0.7501378 0.3206379 0.3379005 |
This file contains hidden or 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
| gistr |
This file contains hidden or 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
| gistr |
This file contains hidden or 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
| gistr |
This file contains hidden or 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
| # modified from https://gist.github.com/sa-lee/c271b47d8065412d3d42c1ad8e63048d | |
| library(datasauRus) | |
| library(gganimate) | |
| library(magrittr) | |
| p <- datasaurus_dozen %>% | |
| ggplot() + | |
| geom_point(aes(x = x, y = y), col = "steelblue") + | |
| theme(legend.position = 'none', | |
| aspect.ratio = 1, |
This file contains hidden or 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
| `+` <- function(e1, e2) { | |
| ## unary | |
| if (missing(e2)) return(e1) | |
| if (!is.na(suppressWarnings(as.numeric(e1))) & !is.na(suppressWarnings(as.numeric(e2)))) { | |
| ## both arguments numeric-like but characters | |
| return(base::`+`(as.numeric(e1), as.numeric(e2))) | |
| } else if ((is.character(e1) & is.na(suppressWarnings(as.numeric(e1)))) | | |
| (is.character(e2) & is.na(suppressWarnings(as.numeric(e2))))) { | |
| ## at least one true character | |
| return(paste0(e1, e2)) |