Skip to contents

Shorthand to add data to a dataset and save as the same name

Usage

data_push(., add, which = c("rows", "cols"))

Arguments

.

first data set

add

data set to add

which

where to append the new data e.g. rows or cols

Value

the combined dataset store to a variable with the name of the first

Examples

# initialize p1 and p2
init(p1,p2)
p1
#> NULL
p2
#> NULL

# declare p1 and p2 as data frame
p1 <- data.frame(PK=1:10,ID2=1:10)
p2 <- data.frame(PK=11:20,ID2=21:30)

p1
#>    PK ID2
#> 1   1   1
#> 2   2   2
#> 3   3   3
#> 4   4   4
#> 5   5   5
#> 6   6   6
#> 7   7   7
#> 8   8   8
#> 9   9   9
#> 10 10  10
p2
#>    PK ID2
#> 1  11  21
#> 2  12  22
#> 3  13  23
#> 4  14  24
#> 5  15  25
#> 6  16  26
#> 7  17  27
#> 8  18  28
#> 9  19  29
#> 10 20  30

#add p1 to p2 by row, and resave as p1
data_push(p1,p2,"rows")
# p2 # p2 remains the same
p1 #p1 has been updated
#>    PK ID2
#> 1   1   1
#> 2   2   2
#> 3   3   3
#> 4   4   4
#> 5   5   5
#> 6   6   6
#> 7   7   7
#> 8   8   8
#> 9   9   9
#> 10 10  10
#> 11 11  21
#> 12 12  22
#> 13 13  23
#> 14 14  24
#> 15 15  25
#> 16 16  26
#> 17 17  27
#> 18 18  28
#> 19 19  29
#> 20 20  30

# declare a new data frame called p3
p3 <- data.frame(Hindex=number(20),Rindex=number(20,seed=20))

# add p3 to p1 as column, and resave as p1
data_push(p1,p3,"cols")
p1 # p1 has been updated
#>    PK ID2    Hindex    Rindex
#> 1   1   1 233952564 547734719
#> 2   2   2 402247333 124422008
#> 3   3   3 189146143 914488057
#> 4   4   4 595329567 392237597
#> 5   5   5 296875954 333274814
#> 6   6   6  82443237 925680127
#> 7   7   7 151994891   8306217
#> 8   8   8  42529469 826438589
#> 9   9   9 986233857 309861357
#> 10 10  10 160983218 168677832
#> 11 11  21 865780800 817042377
#> 12 12  22 732283042  64229841
#> 13 13  23 102472429 674823686
#> 14 14  24 603499467 275229908
#> 15 15  25 511995833 347435685
#> 16 16  26 517447284 361246621
#> 17 17  27 990047365  48331161
#> 18 18  28   8564014 926935286
#> 19 19  29 222140686 650396162
#> 20 20  30 500072143 401738184