I have a variable name subject. For each unique subject there are 240 response latency recorded. Depending on that experimental condition is counterbalanced between-subject. Now I want to read the subject ID (variable name subject) and if they are even I should assign order to be 1 or if the subject ID is odd, I should assign variable order 2. Now this assignment should be done for each rows (ie 240 per subject)
I used if loop: The error I get is…. the condition has length > 1 and only the first element will be used
I also tried ifelse like this:
ifelse(data1$subject%%2==1, data1$order<-1, data1$order<-2)
Though the output is generated but it is not recorded/stored in the variable order.
Please help to make this happen.
I got the answer luckily.
the same ifelse will work in the following manner:
order<-ifelse(data1$subject%%2==1,1,2)
To include the new vector into the dataframe, we can use:
data1<-cbind(data1,order)