I would like to identify activities performed on the same place and with the same person for id during time t. The variable wher denotes time steps and records where the activities take place at time t. The with parameter records the with who the activity was performed at time t. I would like to know the common activities that were performed at the same place and with the same person during time t based on gender. Uncommon activities and activities performed at different place with different person I replaced with 0.
Input
id DMSex t1 t2 t3 t4 wher1 wher2 wher3 wher4 wit1 wit2 wit3 wit4
12 M 12 12 12 12 1 1 1 4 8 9 4 0
12 F 10 13 12 12 3 1 1 5 6 5 4 1
Output:
id t1 t2 t3 t4
12 0 0 12 0
Sample data for 18 time steps:
structure(list(serial = c(11011202, 11011202), DMSex = c(1, 2
), act1_1 = c(110, 110), act1_2 = c(110, 110), act1_3 = c(110,
110), act1_4 = c(110, 110), act1_5 = c(110, 110), act1_6 = c(110,
110), act1_7 = c(110, 110), act1_8 = c(110, 110), act1_9 = c(110,
110), act1_10 = c(110, 110), act1_11 = c(110, 110), act1_12 = c(8219,
110), act1_13 = c(310, 110), act1_14 = c(3210, 110), act1_15 = c(3110,
110), act1_16 = c(7241, 110), act1_17 = c(210, 110), act1_18 = c(3819,
110), wher_1 = c(11, 11), wher_2 = c(11, 11), wher_3 = c(11,
11), wher_4 = c(11, 11), wher_5 = c(11, 11), wher_6 = c(11, 11
), wher_7 = c(11, 11), wher_8 = c(11, 11), wher_9 = c(11, 11),
wher_10 = c(11, 11), wher_11 = c(11, 11), wher_12 = c(11,
11), wher_13 = c(11, 11), wher_14 = c(11, 11), wher_15 = c(11,
11), wher_16 = c(11, 11), wher_17 = c(11, 11), wher_18 = c(11,
11), wit4_1 = c(0, 0), wit4_2 = c(0, 0), wit4_3 = c(0, 0),
wit4_4 = c(0, 0), wit4_5 = c(0, 0), wit4_6 = c(0, 0), wit4_7 = c(0,
0), wit4_8 = c(0, 0), wit4_9 = c(0, 0), wit4_10 = c(0, 0),
wit4_11 = c(0, 0), wit4_12 = c(0, 0), wit4_13 = c(0, 0),
wit4_14 = c(0, 0), wit4_15 = c(0, 0), wit4_16 = c(0, 0),
wit4_17 = c(0, 0), wit4_18 = c(0, 0)), row.names = 1:2, class = "data.frame")
where act1_ is t; wit4 is wit and wher_ is wher