# DataFramesMeta Arthimetic

**URL:** <https://discourse.julialang.org/t/dataframesmeta-arthimetic/31011>\
**Category:** New to Julia\
**Created:** [November 12, 2019, 4:28pm UTC](https://discourse.julialang.org/t/dataframesmeta-arthimetic/31011 "2019-11-12T16:28:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_Sutton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phillip_sutton/32/7603_2.png) [@Phillip\_Sutton](https://discourse.julialang.org/u/Phillip_Sutton)\
**Post date:** [November 12, 2019, 4:28pm UTC](https://discourse.julialang.org/t/dataframesmeta-arthimetic/31011/1 "2019-11-12T16:28:59Z")

</div>

How do you add/subtract/muiltply/divide a column in my dataframe by a scalar?

```julia
@> begin
     dat
    @transform(new_col=:x ./365)

```

throws an error:

> MethodError: no method matching /(::Symbol, ::Int64)

thoughts? just want to convert days to years. Had Similar trouble with +, -, etc.

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [November 12, 2019, 4:55pm UTC](https://discourse.julialang.org/t/dataframesmeta-arthimetic/31011/2 "2019-11-12T16:55:41Z")

</div>

Do you want to do something like this:

```julia
julia> using DataFrames

julia> df = DataFrame(a = rand(3), b = rand(3))
3×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64 │
├─────┼──────────┼──────────┤
│ 1 │ 0.254205 │ 0.843809 │
│ 2 │ 0.454499 │ 0.106612 │
│ 3 │ 0.646103 │ 0.286037 │

julia> df.a ./= 365
3-element Array{Float64,1}:
 0.0006964531670979474
 0.0012452038656085495
 0.0017701452273107896

julia> df
3×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64 │
├─────┼─────────────┼──────────┤
│ 1 │ 0.000696453 │ 0.843809 │
│ 2 │ 0.0012452 │ 0.106612 │
│ 3 │ 0.00177015 │ 0.286037 │

```

or

```julia
julia> using DataFramesMeta

julia> df = @transform df c = :b ./ 365
3×3 DataFrame
│ Row │ a │ b │ c │
│ │ Float64 │ Float64 │ Float64 │
├─────┼─────────────┼──────────┼─────────────┤
│ 1 │ 0.000696453 │ 0.843809 │ 0.00231181 │
│ 2 │ 0.0012452 │ 0.106612 │ 0.000292088 │
│ 3 │ 0.00177015 │ 0.286037 │ 0.000783664 │

```

---

<div class="post-metadata">

**Author:** ![Phillip\_Sutton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phillip_sutton/32/7603_2.png) [@Phillip\_Sutton](https://discourse.julialang.org/u/Phillip_Sutton)\
**Post date:** [November 12, 2019, 7:52pm UTC](https://discourse.julialang.org/t/dataframesmeta-arthimetic/31011/3 "2019-11-12T19:52:15Z")

</div>

The latter is what I was trying to do, but looks like you managed to do it. Maybe it has something to do with my versions?  
Julia v1.0.3 and DataFramesMeta v0.6?

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [November 12, 2019, 7:59pm UTC](https://discourse.julialang.org/t/dataframesmeta-arthimetic/31011/4 "2019-11-12T19:59:48Z")

</div>

I am on Julia v1.2.0 and DataFramesMeta v0.5.0.  
Does the example I posted not work with your version?

I couldn’t try your example, since I don’t have `dat`. But note that in my example the dataframe `df` is the first argument of the marcro `@transform`.
