Problems with recoding of factors

Hello everyone.
I am kind of frustrated. I am working with a colleague and he has been producing some incredible analysis in R.
He has sent me scripts of his work so I can see the analysis, however, I am having nothing but problems getting his scripts to run.
For example, we have a dataframe called ecoreg, which consists of 25 variables and 144 observations. I have attached the script below. His first step is to reorder some of the observations, then creates a set of factors. This script works seamless for him, however, I get the error at the bottom of the script. For some reason, I can create a new factor called 'places', but cannot recode the LBM level to LB. Not sure why? I tried using the 'recode' function of the dplyr package, however, when I tried to use the new factors in analysis it defaulted to the old codes.
Please help! I cannot figure out why the code would work for him, but not for me?

ecoreg2=ecoreg
ecoreg2[37,]=ecoreg[42,]
ecoreg2[38,]=ecoreg[41,]
ecoreg2[39,]=ecoreg[40,]
ecoreg2[40,]=ecoreg[37,]
ecoreg2[41,]=ecoreg[38,]
ecoreg2[42,]=ecoreg[39,]

subregion=ecoreg2[,1]
location=ecoreg2[,2]
lines=ecoreg2[,3]
ecoreg.var=ecoreg2[,9:25]
places=location
places[which(places=="LBM")]="LB"
Warning message:
In [<-.factor(*tmp*, which(places == "LBM"), value = "LB") :
invalid factor level, NA generated

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Hello all.
I figured out the problem. I upgraded my R core version from 3.5 to 4.0.3 and my RStudio to the latest versions. I am surprised that there is that much difference in syntax between older and new versions of R.

Actually, there isn't, it is hard to tell for sure what your problem was, since you haven't provided a reproducible example but I'm glad now is working for you.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.