unite_two_DF: Combine two data frames

Description Usage Arguments Details Value Author(s) Examples

Description

Combine two data frames according to shared variable

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
unite_two_DF(
  data1,
  data1.shared.var,
  data1.shared.column.num = 1,
  data2,
  data2.shared.var,
  data2.shared.column.num = 1,
  delete.not.shared = FALSE,
  not.shared = "all",
  verbose = TRUE
)

Arguments

data1, data2

data frames

data1.shared.var, data2.shared.var

same variables in data frames

data1.shared.column.num, data2.shared.column.num

integer; column numbers of same variables in data frames

delete.not.shared

logical; delete rows that present in one data frame but do not present in other data frame

not.shared

character; which rows to delete; possible values are "data1" (delete rows that present in data1 but do not present in data2), "data2" (delete rows that present in data2 but do not present in data1), "all" (both variants)

verbose

logical; show messages

Details

This function combines columns of two data frames according to shared.var which acts like rows' identification number. If shared.var value from one data frame do not present in other data frame, NAs are produced. Those absent rows are deleted when delete.not.shared = TRUE.

data1.shared.var and data2.shared.var must contain unique values within its own data frame.

Order of rows in resulting data frame is according to data1. data2.shared.var is removed from resulting data frame.

Value

Combined data frame.

Author(s)

Elena N. Filatova

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#same values in shared variables
data1 <- data.frame (N = 1:5, letter = rep("A", 5))
data2 <- data.frame (N = 1:5, letter = rep("B", 5), cs = rep("cs",5))
unite_two_DF (data1 = data1, data1.shared.var = data1$N, data2 = data2, data2.shared.var = data2$N,
            delete.not.shared = TRUE, not.shared = "all")
#different values in shared variables
data1 <- data.frame (N = 1:5, letter = rep("A", 5))
data2 <- data.frame (N = 3:8, letter = rep("B", 6), cs = rep("cs",6))
unite_two_DF (data1 = data1, data1.shared.var = data1$N, data2 = data2, data2.shared.var = data2$N)
unite_two_DF (data1 = data1, data1.shared.var = data1$N, data2 = data2, data2.shared.var = data2$N,
            delete.not.shared = TRUE, not.shared = "data1")
unite_two_DF (data1 = data1, data1.shared.var = data1$N, data2 = data2, data2.shared.var = data2$N,
            delete.not.shared = TRUE, not.shared = "data2")
unite_two_DF (data1 = data1, data1.shared.var = data1$N, data2 = data2, data2.shared.var = data2$N,
            delete.not.shared = TRUE, not.shared = "all")

disprose documentation built on Jan. 6, 2022, 1:07 a.m.