Skip to content
Prev 374767 / 398521 Next

Recoding variables in R

It looks like your data has class "factor".  If you call factor() on a
factor variable, without supplying an explicit 'levels' argument it
produces a new factor variable without any levels not present in the input
factor.  E.g.,
D    C    B    A NA's
   2    0    1    1    2
D    B    A NA's
   2    1    1    2

You can use levels(fNew) <- c("delta","beta","alpha") to give the levels
new names.

I think that renaming "0", "2", "3"  to "0","1","2" will lead to
confusion.  The levels
are just names, so give them names that mean something to a human, like
"control",
"streptomycin (2 mg/kg)", etc.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, May 23, 2018 at 3:14 AM, Lisa van der Burgh <lisavdburgh at hotmail.com

  
  
Message-ID: <CAF8bMcYrNNm3wU-gR=+Ae4+mU0CJAKgCs28rjrHfLeGd0UYPgQ@mail.gmail.com>
In-Reply-To: <AM4PR02MB1684C752B8F31AB97D4E180EA06B0@AM4PR02MB1684.eurprd02.prod.outlook.com>