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