Apply transform() to all DataFrame columns of a certain type?

What’s the ‘standard’ way to apply the transform function to all columns of a certain type in a DataFrame?

For example, the best way to double all numeric columns I could come up with was:

df = DataFrame(a="hello", b=1, c=2, d="world");
transform!(df, names(df, (<:).(eltype.(eachcol(df)), Number)) .=> ByRow(x->2*x), renamecols=false)

Am I overlooking an obvious shortcut here? Also, how would I include a column containing missings?

You can use named(df, T) to get a Vector of all the column names where the eltype isa T

So you would have


julia> df = DataFrame(a="hello", b=1, c=2, d="world");

julia> nms = names(df, Number)
2-element Vector{String}:
 "b"
 "c"

julia> transform!(df, nms .=> ByRow(x -> 2 * x); renamecols = false)
1×4 DataFrame
 Row │ a       b      c      d      
     │ String  Int64  Int64  String 
─────┼──────────────────────────────
   1 │ hello       2      4  world
4 Likes