Most Frequent Text with conditional

Hi Fellows.

I have a huge amount of data and I am new working with R languagem. I would like to have a help for the following issue: I want to Unify rows 4 and 5 (SourceA), based on the condition:

When the cell B4 and B5 have "AA" ; "CC" ; "GG" ; "TT" then get the most frequent in the column of source A range and put into third cell below(Most frequent), make a loop for all cells right until the last column filled.

If B4 or B5 have anything different of "AA" ; "CC" ; "GG" ; "TT" then consider just the cell with the double letter.

Besides that i would like to perform that macro for many Sources in coluns A.

See in the picture the expected result.

Really Thank you in advance.

Without a reprex (see the FAQ), it's difficult to illustrate a solution. In outline,

1, Create a data frame, say dat with Source as rows and "AA" ; "CC" ; "GG" ; "TT" is columns (observations:variables)
2, mutate a new column max_pair with the greatest of max(#the pairs columns)
3. Consider what to do in the event of ties
4. If all pair missing, set max_pair to the desired default value

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.