I need some help with enumerating rows (I hope enumerating is the correct word for this). In my dataframe I have 4 columns and in the 5th I want to save how many times I have the same value in column 4. The values in the second column come always in multiples of 4, so when I have 8 times the same value, I want to have in the 5th Column 1,1,1,1,2,2,2,2. So everytime when I see another value in the 2nd column, I start again with 1 in the 5th column. My data looks like this:
structure(list(TF = c("AT1G18330", "AT1G18330", "AT1G18330",
"AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330",
"AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330",
"AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330",
"AT1G18330", "AT1G18330"), Pos = c("chr1_10050946_10050953",
"chr1_10050946_10050953", "chr1_10050946_10050953", "chr1_10050946_10050953",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854"), Triplet = c("AAAATTAC", "AAAATCAT",
"AAAATCAC", "AAAATTAT", "ATTTTCTA", "TTATTCTA", "TTTTTCTA", "ATATTCTA",
"TTTTTCTA", "ATTTTCAA", "ATTTTCTA", "TTTTTCAA", "TTTTTCTA", "ATCTTCTA",
"ATTTTCTA", "TTCTTCTA", "ATTTTCAA", "ATCTTCTA", "ATTTTCTA", "ATCTTCAA"
), Type = c("genome", "genome", "genome", "build", "genome",
"genome", "genome", "build", "genome", "genome", "genome", "build",
"genome", "genome", "genome", "build", "genome", "genome", "genome",
"build")), row.names = c(NA, -20L), class = c("tbl_df", "tbl",
"data.frame"))
In the end I want to have this:
structure(list(TF = c("AT1G18330", "AT1G18330", "AT1G18330",
"AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330",
"AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330",
"AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330", "AT1G18330",
"AT1G18330", "AT1G18330"), Pos = c("chr1_10050946_10050953",
"chr1_10050946_10050953", "chr1_10050946_10050953", "chr1_10050946_10050953",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854", "chr1_10055847_10055854", "chr1_10055847_10055854",
"chr1_10055847_10055854"), Triplet = c("AAAATTAC", "AAAATCAT",
"AAAATCAC", "AAAATTAT", "ATTTTCTA", "TTATTCTA", "TTTTTCTA", "ATATTCTA",
"TTTTTCTA", "ATTTTCAA", "ATTTTCTA", "TTTTTCAA", "TTTTTCTA", "ATCTTCTA",
"ATTTTCTA", "TTCTTCTA", "ATTTTCAA", "ATCTTCTA", "ATTTTCTA", "ATCTTCAA"
), Type = c("genome", "genome", "genome", "build", "genome",
"genome", "genome", "build", "genome", "genome", "genome", "build",
"genome", "genome", "genome", "build", "genome", "genome", "genome",
"build"), Nr = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3,
3, 4, 4, 4, 4)), row.names = c(NA, -20L), class = c("tbl_df",
"tbl", "data.frame"))
Any help is appreciated!