I have a dataset,prgeng
. 7 columns, 1 of it is educ
.
I want to replace the values of educ
with other values. I need to replace values 1:9 with 1, 10:12 with 2, 13 with 3 and so on.
It doesnt work using the :
operator.
prgeng <- load(url('https://github.com/matloff/fasteR/blob/master/data/prgeng.RData?raw=true'))
educ <- prgeng$educ
educ[educ == 1:9] <- 1 # doesnt work
# Warning: longer object length is not a multiple of shorter object lengthWarning: longer object length is not a multiple of shorter object length
educ[educ == 1] <- 1 # works
I think its weird because this on the other hand works.
t1 <- 1:2500
t1[t1 == 1:1000] <- 1 # this works
I get that the warning is key but i cannot get my head around what its supposed to mean. And other examples here are based on slightly different cases. I dont think it happens because educ
is a factor because:
- i converted educ to a vector and it changed nothing
- Im able to change the values one by one