Spring 2026
y = third_function( second_function( first_function(x) ) )
y1 = first_function(x) y2 = second_function(y1) y = third_function(y2)
suppressWarnings(library(dplyr)) df <- summarise(group_by(mutate(filter(mtcars, cyl==8), efficiency=mpg/wt), carb), AvgEff=mean(efficiency)) head(df)
polynomial1(x) = x.^3 .+ 2*x .- 4 polynomial2(x) = 3*x.^2 .+ 6 function CoolFunction(f) x = rand(Float64, 10) y = f(x) return y end CoolFunction(polynomial1) CoolFunction(polynomial2)
-> operator to perform this argument mapping# Find first gives you the range of the first instance of a pattern in a longer list
findfirst("Turtle", "Teenage Mutant Ninja Turtles")
d = rand(10) # How can I find the first range of values > 0.75?
# Each time a pattern is compared, the x>0.75 function is run,
# where "x" is whatever element from d it selected
findfirst(x -> x>0.75, d)
x>0.75 code doesn’t have a name, hence anonymousmylist = []; for val in d push!(mylist, (val>0.5) + 0); end
map function in Julia says “apply this code to every element in list”d = rand(10); mylist = map(x -> x>0.5, d) # BTW, ths is equivalent to d.>0.5
mylist = [x>0.5 for x in d]
do Block in Juliamap([A, B, C]) do x
if x < 0 && iseven(x)
return 0
elseif x == 0
return 1
else
return x
end
end
x in the blockMore Info: https://docs.julialang.org/en/v1/manual/functions/
lambdaimport numpy as np d = np.random.uniform(size=10) list(filter(lambda x: x>0.75, d))
x>0.75 for item in d, treating that item as xfruits = ["apple", "banana", "cherry", "kiwi", "mango"] newlist = [x for x in fruits if "a" in x]
fruits = ["apple", "banana", "cherry", "kiwi", "mango"] newlist = [] for x in fruits: newlist.append(x)
%>%|>, like in JuliaMore Info: https://malooflab.ucdavis.edu/apps/tidyverse-tutorial/
library(tidyverse) mtcars %>% .$mpg
suppressWarnings(library(dplyr))
suppressWarnings(library(tidyverse))
df <- mtcars %>%
filter(cyl==8) %>%
mutate(efficiency=mpg/wt) %>%
group_by(carb) %>%
summarize(AvgEff=mean(efficiency))
head(df)
%>% as first operator in a line for R syntax reasonssuppressWarnings(library(dplyr))
suppressWarnings(library(tidyverse))
df <- starwars %>%
filter(species == "Human") %>%
mutate(bmi=mass/height^2) %>%
group_by(homeworld) %>%
summarise(AvgBMI=mean(bmi)) %>%
arrange(AvgBMI)
head(df)
Handy Tidyverse Cheatsheet: https://github.com/rstudio/cheatsheets/blob/main/data-transformation.pdf
f(x) = x.^2 g(x) = 3*x .+ 2 h(x) = sum(x) # This: h(f(g([1,2]))) # Is the same as: [1,2] |> g |> f |> h
f(x,y) = x.^2 .+ y g(x) = 3*x .+ 2 h(x) = sum(x) h( f( g([1,2]), 5) ) [1,2] |> g |> a->f(a,5) |> h
using DataFrames, RDatasets, Statistics
df = dataset("datasets", "mtcars") |>
filter(row -> row.MPG>25) |>
x->transform(x, [:MPG, :WT] => (a,b) -> a./b) |>
x->groupby(x, :Carb) |>
x->combine(x,:MPG_WT_function=>mean)
head(df)
[:Col1, :Col2] => (a,b) -> a./b) means: Use Col1 of the data frame as argument a, use Col2 as arg b, then perform vectorized division between those two to make a new valuex->func(x, args) means map the co-domain as the x argument to func