New Dataframe Column from a View from Another DataFrames

Hi all,

I have a dataframe and a column view of a another dataframe B like this:

A = DataFrame([1 3 5; 1 3 5; 2 4 6; 2 4 6;])
C = @view B[col]

A looks like this:

4×3 DataFrame
 Row │ x1     x2     x3
     │ Int64  Int64  Int64
─────┼─────────────────────
   1 │     1      3      5
   2 │     1      3      5
   3 │     2      4      6
   4 │     2      4      6

C looks like this:

[7, 8]

What I want to create is something that looks like this from C:

4×4 DataFrame
 Row │ x1     x2     x3     x4
     │ Int64  Int64  Int64  Int64
─────┼─────────────────────
   1 │     1      3      5       7
   2 │     1      3      5       7
   3 │     2      4      6       8
   4 │     2      4      6       8

Where x4 is constructed entirely from viewed values. Is this possible to do? And if so, how?

Thanks!

~tcp :deciduous_tree:

First, note that the fact that this works means you aren’t on the newest version of DataFrames (assuming B is a DataFrame)

It looks like you can do this, with !

julia> using DataFrames

julia> df = DataFrame();

julia> x = [1, 2, 3, 4];

julia> y = @view x[1:2]
2-element view(::Array{Int64,1}, 1:2) with eltype Int64:
 1
 2

julia> df[!, :a] = y;

julia> df.a
2-element view(::Array{Int64,1}, 1:2) with eltype Int64:
 1
 2