@williaml @jmcvw
Sorry, I've added a small example of what I would like the data to look like!
## subject = subject number, key = button they pressed, test_part = block or question row, value = new column with value (1, 2 or NA)
subject = factor(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4))
key = c(4, 4, 4, 4, 4, 1, 5, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 4, 5, 4, 4, 5, 2, 4, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4, 4, 5, 5, 5, 4, 1, 4, 4, 5, 5, 4, 2)
test_name = c("block", "block", "block", "block", "block", "question", "block", "block", "block", "block", "block", "question", "block", "block", "block", "block", "block", "block", "block", "block", "block", "block", "question", "block", "block", "block", "block", "block", "question", "block", "block", "block", "block", "block", "block", "block", "block", "block", "block", "question", "block", "block", "block", "block", "block", "question")
value = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, NA, NA, NA, NA, NA, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, NA, NA, NA, NA, NA, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2)
df = data.frame(subj, key, test_name, value)
df
In the example, I've excluded the other elements of my dataframe, keeping just the relevant columns needed. The "value" column would be the new column.
I tried using @jmcvw method on my dataset and I think I did something wrong somewhere... The "m" dataframe has a column that contains numbers ranging from 90-1500 (similar to how many rows there are total in my dataframe) and another column that just has a value of "16". When I combined the "m" and my dataframe together, the new column has a mix of values of "c(5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 4, 5, 5, 5)" and "NA" thrown around randomly. It works on the "d" dataset that was provided though.
Thanks!