-4

i need to split data into multiple persons with the reference data set

Data 1

Numbers
680
183
856
661
916
240
68
390
393
722
241
627
77
439
162
943
185
931
117

Data 2

Team
A
B
C
D

Output

Numbers Team
680 A
183 A
856 A
661 A
916 A
240 B
68  B
390 B
393 B
722 B
241 C
627 C
77  C
439 C
162 C
943 D
185 D
931 D
117 D
zx8754
  • 52,746
  • 12
  • 114
  • 209
Arun
  • 1
  • 3

1 Answers1

0

Use rep() in combination with the each- and length-out-arguments

In this example I used data.table.

sample data

library(data.table)
dt <- fread("Numbers
680
183
856
661
916
240
68
390
393
722
241
627
77
439
162
943
185
931
117")

team <- fread("Team
A
B
C
D")[[1]]

code

dt[, Team := rep( team, 
                  each = ceiling( nrow(dt)/length(team) ), 
                  length.out = nrow(dt) )]

output

#     Numbers Team
#  1:     680    A
#  2:     183    A
#  3:     856    A
#  4:     661    A
#  5:     916    A
#  6:     240    B
#  7:      68    B
#  8:     390    B
#  9:     393    B
# 10:     722    B
# 11:     241    C
# 12:     627    C
# 13:      77    C
# 14:     439    C
# 15:     162    C
# 16:     943    D
# 17:     185    D
# 18:     931    D
# 19:     117    D
Wimpel
  • 26,031
  • 1
  • 20
  • 37