0

I'm trying to do some data analysis of a memory experiment. Essentially, participants saw screens where six images - two from one of each of three categories, one of which is faces. They were asked to remember them. Later on, their memory was tested, and the answer was logged as correct or wrong. In all, participants who completed the whole experiment, saw 54 of these screens. For the analysis, I need to code which stimuli were presented in which encoding screen. I have managed to this for one example participant.

Here is the code that I used for the one participant:

beh_data[beh_data$face1!="","screennumber"]=1:54

However, when trying to extend the code, certain participants - who did not manage to complete the whole experiment, and thus did not see all 54 screens - caused a problem. I run into:

Error in [<-.data.frame(*tmp*, beh_data$face1 != "", "screennumber", : missing values are not allowed in subscripted assignments of data frames

How can I adapt this code, so that the 1:54 starts over for every participant is the dataset? Thank you.

  • I suspect that this problem could be solved using the `dplyr` functions `group_by`, `mutate` and `row_number`. But it's difficult to say without seeing [some example data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) from `beh_data`. – neilfws Mar 15 '21 at 23:32
  • It would be easier to help if you create a small reproducible example along with expected output. Read about [how to give a reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Mar 16 '21 at 04:50

1 Answers1

0

beh_data$face1 likely contain NA's, try this instead:

beh_data[ ! beh_data$face1 %in% "","screennumber"]=1:54
Sirius
  • 5,224
  • 2
  • 14
  • 21