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

**URL:** <https://discourse.julialang.org/t/apply-transform-to-all-dataframe-columns-of-a-certain-type/59433>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [April 16, 2021, 7:03pm UTC](https://discourse.julialang.org/t/apply-transform-to-all-dataframe-columns-of-a-certain-type/59433 "2021-04-16T19:03:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![florian](https://avatars.discourse-cdn.com/v4/letter/f/898d66/32.png) [@florian](https://discourse.julialang.org/u/florian)\
**Post date:** [April 16, 2021, 7:03pm UTC](https://discourse.julialang.org/t/apply-transform-to-all-dataframe-columns-of-a-certain-type/59433/1 "2021-04-16T19:03:00Z")

</div>

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:

```julia
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?

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [April 16, 2021, 7:15pm UTC](https://discourse.julialang.org/t/apply-transform-to-all-dataframe-columns-of-a-certain-type/59433/2 "2021-04-16T19:15:22Z")

</div>

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

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

```
