[R] Renaming levels of a factor in a dataframe

B Jessop deelman at hotmail.com
Sun Aug 14 17:56:25 CEST 2011



Dear Helplist:

 

I am trying, unsuccessfully, to rename levels of a factor in a dataframe. The dataframe consists of two factor variables and one numeric variable as follows:

Factor Site has 2 levels AB and DE, factor Fish has 30 levels, 15 associated with each Site e.g. 1-1, 1-2,.....2-1, 2-2....  I am trying to rename the levels of factor Site from AB to Fw and DE to Est while keeping them as factors.  The following 2 approaches do not work, each giving a NULL response and creating a character string.    

 

levels (Data1$Site <- c("Fw", "Est"))  This simply gives an alternating list of Fw, Est, Fw, Est... not the desired 15 concurrent rows of Fw followed by 15 of Est.

 

#levels (Data1$Site <- list(Fw = "AB", Est = "DE")) This gives the same result.  I have tried other approaches to no avail.  It seems a simple problem but has not been so. 

 

Any suggestions for solving this problem would be much appreciated.

 

Regards,

BJ 		 	   		  


More information about the R-help mailing list