Julia is the equivalent of dplyr bind_cols and bind_rows

Is there Julia's equivalent of dplyr bind_cols and bind_rows? Specifically, I'm looking for a bind_rows function that will match column names regardless of order, and fill NA for non-matching columns

Edit: R Example of both:

library(dplyr)
df1 = data.frame(a = 1, b = 1)
df2 = data.frame(b = 1, c = 1)
df3 = data.frame(c = 1, d = 1)

bind_rows(df1, df2)

   a b  c
1  1 1 NA
2 NA 1  1

bind_cols(df1, df3)

  a b c d
1 1 1 1 1

      

+3


source to share


1 answer


Perhaps, Julia features vcat

and hcat

will meet your requirements.



julia> using DataFrames

julia> df1 = DataFrame(a = 1, b = 1)
1x2 DataFrames.DataFrame
| Row | a | b |
|-----|---|---|
| 1   | 1 | 1 |

julia> df2 = DataFrame(b = 1, c = 1)
1x2 DataFrames.DataFrame
| Row | b | c |
|-----|---|---|
| 1   | 1 | 1 |

julia> df3 = DataFrame(c = 1, d = 1)
1x2 DataFrames.DataFrame
| Row | c | d |
|-----|---|---|
| 1   | 1 | 1 |

julia> vcat(df1, df2)
2x3 DataFrames.DataFrame
| Row | a  | b | c  |
|-----|----|---|----|
| 1   | 1  | 1 | NA |
| 2   | NA | 1 | 1  |

julia> hcat(df1, df3)
1x4 DataFrames.DataFrame
| Row | a | b | c | d |
|-----|---|---|---|---|
| 1   | 1 | 1 | 1 | 1 |

      

+1


source







All Articles