[R] Query about substituting characters in a df

rolf at math.unb.ca rolf at math.unb.ca
Mon Mar 12 22:53:38 CET 2007


Lalitha Viswanath wrote:

> I have a data frame with 40,000 rows and 4 columns,
> one of which is "class".
> 
> For each row, the "class" column can be one of 10 possible NUMERIC
> values.  I wish to substitute these numeric values with
> words/characters.  For example, I wish to substitute all occurences
> of "5467" in the column "class" with "alpha", "7867" with "gamma",
> etc.  I looked up substitute, but did not find any relevant
> examples.

The substitute() function has nothing whatever to do with your
problem.

The following may give you the right idea:

        > xxx <- sample(1:10,100,TRUE)
        > yyy <- letters[1:10][match(xxx,1:10)]

                                cheers,

                                        Rolf Turner
                                        rolf at math.unb.ca



More information about the R-help mailing list