[R] Label rows of table by factor level for groups of factors
O'Hanlon, Simon J
simon.ohanlon at imperial.ac.uk
Tue Mar 6 17:06:41 CET 2012
I am sure this is a fairly simple problem, but I just cannot get my head around it.
I have a dataframe which contains several factor variables. I can use table() to tell me how many different combinations there are of these variables. What I should like to do is to add a column to my original dataframe which labels each row according to the unique combination of factors.
E.g. in the simple example below I create a dataframe 'df' with 3 columns, the values of which take 0 or 1. I can then classify each row in the table and I find that I have 4 unique combinations of factors. I would now like to add a fourth column to df which labels each row according to whether it was unique combination 1,2,3 or 4:
I realise that this is probably quite simple to do, I am just struggling to get my head around it! Help much appreciated in advance.
Simon O'Hanlon BSc, MSc
Department of Infectious Disease Epidemiology
Imperial College London
St. Mary's Hospital
More information about the R-help