Data context: People responding to teach other on an online discussion board
Aim: Filter the data based on whether they took turns within the same post and who the partners (dyad) were. Essentially, it boils down to filtering based on the values of other columns.
Specifically, I thought it would start from checking whether 'turntaking'==1, and then keeping observations with the same 'dyad_id' within the same 'post_id'. I'm having trouble how to filter by multiple conditions.
Example data:
structure(list(post_id = c(100, 230, 100, 100, 100, 100), dyad_id = structure(c(2L,
2L, 2L, 1L, 1L, 1L), .Label = c("42_27", "53_27"), class = "factor"),
dyad_id_order = structure(c(4L, 4L, 2L, 3L, 1L, 3L), .Label = c("27_42",
"27_53", "42_27", "53_27"), class = "factor"), turntaking = c(0,
0, 1, 0, 1, 1)), class = "data.frame", row.names = c(NA,
-6L), variable.labels = structure(character(0), .Names = character(0)), codepage = 65001L)
The example data look like visually:
╔═════════╦═════════╦═══════════════╦════════════╦══════════════════════════════════════════════════════════╗
║ post_id ║ dyad_id ║ dyad_id_order ║ turntaking ║ (note) ║
╠═════════╬═════════╬═══════════════╬════════════╬══════════════════════════════════════════════════════════╣
║ 100 ║ 53_27 ║ 53_27 ║ 0 ║ Keep ║
╠═════════╬═════════╬═══════════════╬════════════╬══════════════════════════════════════════════════════════╣
║ 230 ║ 53_27 ║ 53_27 ║ 0 ║ Drop ║
╠═════════╬═════════╬═══════════════╬════════════╬══════════════════════════════════════════════════════════╣
║ 100 ║ 53_27 ║ 27_53 ║ 1 ║ Keep: ID27 responded to ID53's response in the first row ║
║ ║ ║ ║ ║ (They are both found under the same post_id) ║
╠═════════╬═════════╬═══════════════╬════════════╬══════════════════════════════════════════════════════════╣
║ 100 ║ 42_27 ║ 42_27 ║ 0 ║ Keep ║
╠═════════╬═════════╬═══════════════╬════════════╬══════════════════════════════════════════════════════════╣
║ 100 ║ 42_27 ║ 27_42 ║ 1 ║ Keep ║
╠═════════╬═════════╬═══════════════╬════════════╬══════════════════════════════════════════════════════════╣
║ 100 ║ 42_27 ║ 42_27 ║ 1 ║ Keep ║
╚═════════╩═════════╩═══════════════╩════════════╩══════════════════════════════════════════════════════════╝
The final output would look like:
╔═════════╦═════════╦═══════════════╦════════════╗
║ post_id ║ dyad_id ║ dyad_id_order ║ turntaking ║
╠═════════╬═════════╬═══════════════╬════════════╣
║ 100 ║ 53_27 ║ 53_27 ║ 0 ║
╠═════════╬═════════╬═══════════════╬════════════╣
║ 100 ║ 53_27 ║ 27_53 ║ 1 ║
╠═════════╬═════════╬═══════════════╬════════════╣
║ 100 ║ 42_27 ║ 42_27 ║ 0 ║
╠═════════╬═════════╬═══════════════╬════════════╣
║ 100 ║ 42_27 ║ 27_42 ║ 1 ║
╠═════════╬═════════╬═══════════════╬════════════╣
║ 100 ║ 42_27 ║ 42_27 ║ 1 ║
╚═════════╩═════════╩═══════════════╩════════════╝