I have two data frames:
>old
response RT sNumber blockNo
tiger 170 1 1
tornado 36 1 2
tiger 43 1 3
squire 34 2 1
tiger 48 2 2
tornado 49 2 3
tornado 45 3 1
mouse 66 3 2
tiger 75 3 3
>new
response sNumber blockNo
tiger 1 1
tornado 1 2
squire 2 1
tiger 2 2
tornado 3 1
mouse 3 2
tiger 3 3
In new there are fewer raws. I want to copy RT column from old and perform a mapping by response column to new by keeping correct values of RT corresponding to the unique sNumber and blockNo. It should look like this:
>new2
response RT sNumber blockNo
tiger 170 1 1
tornado 36 1 2
squire 34 2 1
tiger 48 2 2
tornado 45 3 1
mouse 66 3 2
tiger 75 3 3
Usually for mapping I use this loop:
for(wrd in unique(old$response)){
new$RT[new$response == wrd] <- old$RT[old$response == wrd]
}
However, in this particular case it messes up all RT values since it adds up them successively without checking for the unique blockNo and sNumber. How should I perform the mapping of RT in a way that I have described?