0

I have 5 columns of data set and want to group by on two of those. I have no problem in grouping them but I want to assign a incremental flag value to each of those group so I can apply my function later on each of the groups according to the flag. I am facing problem in assigning a flag. Here is the data.

A    B    C    D    E
abc  def  u    10   12
abc  def  v     3   32
abc  def  x     12  3
abc  def  y     13  45
abc  ghi  z     23  12
......

So here, for abc & def I want the flag column value as '1'. For abc & ghi I want the flag column value as '2' and so on.

Please let me know if I have asked the question in correct way so I can rephrase it. Thanks a tonn!

Abhishek Singh
  • 187
  • 2
  • 13
  • Yeah Ronak, the data goes on for thousand of entries with 6 or 7 rows in each. So I want to keep on increasing the flag value as in 1,2,3,4,5.... and so on. – Abhishek Singh Mar 28 '17 at 10:31
  • 3
    The first answer from the link. `transform(df, flag = as.numeric(interaction(A, B, drop=TRUE)))` – Ronak Shah Mar 28 '17 at 10:34
  • Great! Thanks Ronak :) I guess I didn't know exactly what should I look for to get the answer. Thanks a lot! – Abhishek Singh Mar 28 '17 at 10:43
  • In this data I want to do chi sq test. I think it would help me to have flag and group them by but it became tedious. Do you have any idea on how to take them as chunk and then apply chi sq on each of them maybe with or without loop? – Abhishek Singh Mar 29 '17 at 14:31

0 Answers0