How to recategorize a labelled variable and assign new labels?

0

My question is very basic and is as follows: I have a labelled variable with ten levels and different labels and I would like to add two levels to their levels and assign new labels to each of the levels. how can I do this?

    
asked by anonymous 31.08.2017 / 15:54

1 answer

2

It may not be the best code, but it does the job:

niveis <- data.frame(Antigo = letters[1:10])
a <- data.frame(Niveis = niveis,
              Novo = paste0(rep("NV", 10), rep(1:5,each = 2)))
merge(niveis, a, by = "Antigo", all.x = T)

   Antigo  Novo
        a  NV1
        b  NV1
        c  NV2
        d  NV2
        e  NV3
        f  NV3
        g  NV4
        h  NV4
        i  NV5
        j  NV5

The best code will depend on whether your variable is in a data frame or not

    
25.10.2018 / 02:26