I'm trying to use the replace command to replace factor levels with an associated value. I have 3 variables in my data frame that I'm trying to do this for, and 2 worked perfectly but the third is giving me the following error:
Warning message:
In `[<-.factor`(`*tmp*`, list, value = c(11.76, 13.56, -1.64, -14.04, :
invalid factor level, NA generated
Any thoughts why that might be?
data:
Outfit Wearer Color Score
1 E 1 R 64
2 E 2 G 75
3 E 3 W 71
4 E 4 Bk 93
5 E 5 Bu 86
6 H 1 W 90
Code:
new.dat$Color <- replace(new.dat$color, col.m[,1], col.m[,3])
new.dat$Wearer <- replace(new.dat$Wearer, wear.m[,1], wear.m[,3])
new.dat$Outfit <- replace(new.dat$Outfit, out.m[,1], out.m[,3])
The last one, Outfit is not working. This is what out.m looks like:
Group.1 x dev
1 B 52.0 -14.04
2 E 77.8 11.76
3 H 79.6 13.56
4 J 56.4 -9.64
5 S 64.4 -1.64
I also tried to 'trim' the vector and matching index in case it was a white space issue, but that didn't help.
Thank you for any thoughts!