I have problem with adding a matrix I created using tappy fuction. The following is the code I run:
colnames(learningblock)
learningblock$uniquecode <- paste(learningblock$subject,learningblock$condition,learningblock$index,sep="_")
colnames(learningblock)
head(learningblock)
FF2 = learningblock[learningblock$CURRENT_FIX_INDEX == 1 | learningblock$CURRENT_FIX_INDEX == 2,]
FF2.1=FF2[FF2$CURRENT_FIX_INTEREST_AREA_FIX_COUNT>1,]
head(FF2.1)
FF2.2=FF2.1
sum.matrix = tapply(FF2.2$CURRENT_FIX_DURATION, FF2.2$uniquecode, sum, na.rm = T)
FF2.2$sum.matrix <- rep(sum.matrix, each=2)
head(FF2.2)
What I aimed to do is the sum the numbers based on "uniquecode", for example, from the oupput image I added, I want to do 236+643=879; 190+387=577...., but when I checked the column of sum.matrix the numbers look not correct it should not be 698, 512... I guess the sum.matrix doesn't match the unicode when I added into the dataframe. Can you help you to sort this out?
Thank you very much!