#c++ifelse
The base #RStats pipe (`|>`) is so stupid cool.
April 5, 2025 at 7:15 PM
How do you use if, else, and switch in C++?
tpointtech.wordpress.com/2025/06/05/h...

#ifelsecpp #c++ifelse
June 6, 2025 at 7:06 AM
In R, in many contexts, missing values throw an exception or pass through to result vector. Like:

x <- c(2,0,NA,3)
ifelse(x>1,1,0)
[1] 1 0 NA 1
December 18, 2025 at 11:05 AM
lol oh no

my first thought is, yours is worst-case quadratic if x is all NA, but linear if there are no NAs

so just throw outer() at it so it's always quadratic:
February 24, 2026 at 6:52 AM
My current Foundry struggle:

Old Dice Parser: X < Y && Z < A ? B : C
New Dice Parser: ifelse(and(lt(X, Y), lt(Z, A)), B, C)

These say the same thing, but I find the first one significantly more understandable than the latter v_v
March 20, 2025 at 5:58 PM
Day 5 of #30DayMapChallenge
Theme: A Journey
Response: Journey's Journey 2024 - The 73(!) venues being played by the band Journey in 2024. Concert details from setlist.fm/search?artist=3d6b507&upcoming=true&year=2024 with a bunch of additional getting venue coordinates as commitment to the bit.
November 4, 2024 at 6:19 PM
FYI: For N=1000, I changed "after" to:

after = before + ifelse(before>=5, 0, sample(c(-1, 0, 1), sample_size, replace = TRUE)),
July 2, 2024 at 10:33 PM
The base #rstats pipe (`|>`) is so stupid cool.
April 5, 2025 at 7:15 PM
Here's my standard bit of code for pulling out the original categories for Germany but you can just delete stuff. Line 23 is the part you want, I think.
May 8, 2025 at 1:49 PM
Trying #adventofcode in R. Monstrous solution to part two of day 1:

x = readr::read_lines("input.txt")
xdir = substring(x,1,1)
xlen = as.numeric(substring(x,2))
xcum = cumsum(c(50,xlen*ifelse(xdir=="L",-1,1)))
sum(
0.5 * abs(diff(floor(xcum / 100))) +
0.5 * abs(diff(floor((xcum-1) / 100)))
)
December 1, 2025 at 6:58 PM
Day 6: the first #adventofcode puzzle I've done where the bulk of the puzzle was parsing the input data. I enjoyed this one a lot! #rstats
December 8, 2025 at 6:20 PM
A bit more tweaking- using ggpattern (and alpha to mute it on the non-Don't Knows) to make it a bit clearer than for these purposes not giving a definitive answer is considered a different thing, and tweaking the Trust level factor/colour order.
A bit of the key #rstats graph making code in alt text
November 3, 2025 at 10:33 PM
i dont even know anymore
June 3, 2025 at 9:43 PM
# unpipe-y
age_bin <- age_months %/% 12
age_bin <- ifelse(age_bin > 7, 7, age_bin)

# pipe-y
age_bin <- (age_months %/% 12) |> pmin(7)

age_bin <- (a$age_months %/% 12) |>
scales::oob_squish(range = c(NA, 7))
April 5, 2024 at 3:31 PM
```
r = c('R' = 'LRL', 'L'='LRR')
x = 'RRRR'
for (i in 1:8) {
moves = strsplit(x, '')[[1]]
angles = c(); a = 0
for (m in moves) {
a = a + pi/2 * ifelse(m == "R", -1, 1)
angles = c(angles, a)
}
x = paste(r[strsplit(x, "")[[1]]], collapse = "")
plot(c(0 […]

[Original post on mastodon.social]
May 23, 2025 at 11:46 AM
I love R, but the behaviour of ifelse when you combine scalars and vectors is really unintuitive. E.g., Guess the result of the line behaviour.

ifelse(1 == 2, "Yes", c("Yes", "No"))
February 23, 2026 at 8:02 PM
8/ Now reshape it:
library(tidyr); library(dplyr)
df_tidy <- df %>%
pivot_longer(-strain,
names_to=c("genotype","min","rep"),
names_pattern="(.*)_(\\d+)_?(\\d*)") %>%
mutate(genotype=ifelse(grepl("normal",genotype),"normal","mutant"),
rep=ifelse(rep=="","1",rep))
December 23, 2025 at 2:45 PM
8/ Now reshape it:
library(tidyr); library(dplyr)
df_tidy <- df %>%
pivot_longer(-strain,
names_to=c("genotype","min","rep"),
names_pattern="(.*)_(\\d+)_?(\\d*)") %>%
mutate(genotype=ifelse(grepl("normal",genotype),"normal","mutant"),
rep=ifelse(rep=="","1",rep))
August 24, 2025 at 1:45 PM
[3]

ft_dt$disp <- ifelse(
ft_dt$disp > 200,
cell_spec(ft_dt$disp, color = "red", bold = T),
cell_spec(ft_dt$disp, color = "green", italic = T)
)
ft_dt$hp <- color_bar("lightgreen")(ft_dt$hp)
ft_dt <- ft_dt[c("car", "mpg", "cyl", "disp", "hp")]

to be continued
December 4, 2024 at 3:00 PM