Combining data sets without using row.name
You need neither to use the row names or to create an additonal ID column. Here is an approach based on the indices of the training set.

An example data set:

set.seed(1)
dat &lt;- data.frame(Y = rnorm(10),
                  X1 = rnorm(10),
                  X2 = rnorm(10),
                  Z1 = rnorm(10),
                  Z2 = rnorm(10))


Now, your steps:


Create an analysis data set without the Z variables

dat2 &lt;- dat[grep("Z", names(dat), invert = TRUE)]
dat2
#             Y          X1          X2
# 1  -0.6264538  1.51178117  0.91897737
# 2   0.1836433  0.38984324  0.78213630
# 3  -0.8356286 -0.62124058  0.07456498
# 4   1.5952808 -2.21469989 -1.98935170
# 5   0.3295078  1.12493092  0.61982575
# 6  -0.8204684 -0.04493361 -0.05612874
# 7   0.4874291 -0.01619026 -0.15579551
# 8   0.7383247  0.94383621 -1.47075238
# 9   0.5757814  0.82122120 -0.47815006
# 10 -0.3053884  0.59390132  0.41794156

Break this data set into random training and test sets

train_idx &lt;- sample(nrow(dat2), 0.8 * nrow(dat2))
train_idx
# [1]  7  4  3 10  9  2  1  5

train &lt;- dat2[train_idx, ]
train
#             Y          X1          X2
# 7   0.4874291 -0.01619026 -0.15579551
# 4   1.5952808 -2.21469989 -1.98935170
# 3  -0.8356286 -0.62124058  0.07456498
# 10 -0.3053884  0.59390132  0.41794156
# 9   0.5757814  0.82122120 -0.47815006
# 2   0.1836433  0.38984324  0.78213630
# 1  -0.6264538  1.51178117  0.91897737
# 5   0.3295078  1.12493092  0.61982575

test_idx &lt;- setdiff(seq(nrow(dat2)), train_idx)
test_idx
# [1] 6 8

test &lt;- dat2[test_idx, ]
test
#            Y          X1          X2
# 6 -0.8204684 -0.04493361 -0.05612874
# 8  0.7383247  0.94383621 -1.47075238

Find my best model

...
Predict on both the training and test sets using this model

...
Recombine the training and test sets by rows

idx &lt;- order(c(train_idx, test_idx))
dat3 &lt;- rbind(train, test)[idx, ]
identical(dat3, dat2)
# [1] TRUE

Recombine these data with the Z variables, by column

dat4 &lt;- cbind(dat3, dat[grep("Z", names(dat))])
identical(dat, dat4)
# [1] TRUE



In summary, we can use the indices of the training and test data to combine the data in the rows in the original order.