# Setting multiple columns in DataFrames

**URL:** https://discourse.julialang.org/t/setting-multiple-columns-in-dataframes/5046
**Category:** General Usage
**Created:** [July 24, 2017, 7:42pm UTC](https://discourse.julialang.org/t/setting-multiple-columns-in-dataframes/5046 "2017-07-24T19:42:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mirestrepo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mirestrepo/32/617_2.png) [@mirestrepo](https://discourse.julialang.org/u/mirestrepo)
#### Post date: [July 24, 2017, 7:42pm UTC](https://discourse.julialang.org/t/setting-multiple-columns-in-dataframes/5046/1 "2017-07-24T19:42:22Z")

</div>

Is there a one-line way to set multiple columns of DataFrame row?  
Seems like a trivial question, but can’t find a way to do it.

Suppose I have:

`df = DataFrame(a = [5, 6, 7], b = [55, 66, 77])`

The following and any similar approach I try throws an error

`df[1, :] = [999, 888]`

`ERROR: MethodError: Cannot `convert` an object of type Array{Int64,1} to an object of type Int64 This may have arisen from a call to the constructor Int64(...), since type constructors fall back to convert methods.`

Thanks!

---

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [July 24, 2017, 7:59pm UTC](https://discourse.julialang.org/t/setting-multiple-columns-in-dataframes/5046/2 "2017-07-24T19:59:26Z")

</div>

One way is just to define it:

```julia
julia> setrow!(df::DataFrame,row::Int,val::Vector) = ( foreach(i->df[row,i]=val[i],1:length(df)) ; df )
setrow! (generic function with 1 method)

julia> setrow!(df,1,[999,888])
3×2 DataFrames.DataFrame
│ Row │ a │ b │
├─────┼─────┼─────┤
│ 1 │ 999 │ 888 │
│ 2 │ 6 │ 66 │
│ 3 │ 7 │ 77 │

```
