2
votes

Inputs are:

x <- data.frame(
   input.number = c(0,1,2,1,1),
   input.layer = c(0.0,0.0,0.0,0.0,0.5),
   output.number = c(1,1,1,1,1),
   output.layer = c(1.0,1.0,1.0,0.5,1.0),
   weights = c(-4.9076530,-2.8328544 ,-0.8687123,-2.8328544,-2.8328544)
)
y <- data.frame(
   input.number = 2,
   input.layer = 0,
   output.number = 1,
   output.layer = 0.5,
   weights = 0
)

When joining them by running:

dplyr::full_join(x, y, by = c("input.number", "input.layer", "output.number", "output.layer"), suffix = c('','.dupe'))

The result is a data.frame with duplicated columns:

   input.number input.layer output.number output.layer    weights weights.dupe
 1            0         0.0             1          1.0 -4.9076530           NA
 2            1         0.0             1          1.0 -2.8328544           NA
 3            2         0.0             1          1.0 -0.8687123           NA
 4            1         0.0             1          0.5 -2.8328544           NA
 5            1         0.5             1          1.0 -2.8328544           NA
 6            2         0.0             1          0.5         NA            0

Since the new line is not a dupe I was expecting something like this:

   input.number input.layer output.number output.layer    weights
 1            0         0.0             1          1.0 -4.9076530           
 2            1         0.0             1          1.0 -2.8328544           
 3            2         0.0             1          1.0 -0.8687123           
 4            1         0.0             1          0.5 -2.8328544           
 5            1         0.5             1          1.0 -2.8328544           
 6            2         0.0             1          0.5         0
1

1 Answers

1
votes

The full_join function works fine. However, it looks like the bind_rows function from the package is what your are looking for since x and y have the same column names and you want to add "a new line" to the data frame.

dplyr::bind_rows(x, y)

#   input.number input.layer output.number output.layer    weights
# 1            0         0.0             1          1.0 -4.9076530
# 2            1         0.0             1          1.0 -2.8328544
# 3            2         0.0             1          1.0 -0.8687123
# 4            1         0.0             1          0.5 -2.8328544
# 5            1         0.5             1          1.0 -2.8328544
# 6            2         0.0             1          0.5  0.0000000

Or you can just use the rbind function from the base R.

rbind(x, y)
#   input.number input.layer output.number output.layer    weights
# 1            0         0.0             1          1.0 -4.9076530
# 2            1         0.0             1          1.0 -2.8328544
# 3            2         0.0             1          1.0 -0.8687123
# 4            1         0.0             1          0.5 -2.8328544
# 5            1         0.5             1          1.0 -2.8328544
# 6            2         0.0             1          0.5  0.0000000