http://rstudio.github.io/DT/010-style.htmlに記載されている例の次のステップとして、下の図に示すように、フィルタ値に基づいてセル内の文字列の一部を強調表示したい。私は表形式で生物学的配列データの特定のモチーフを強調しようとしています。以下は、ExcelのVBAコードと代表的な画像です。 Rでこれを達成することは可能ですか?フィルタ値に基づいてセルコンテンツ内の文字列の一部を強調表示
Sub SequencePartColourMacro()
Dim Col, Row, FirstRow, LastRow As Integer, Col As Long
Col = 6
FirstRow = 2
LastRow = ThisWorkbook.Sheets("Sequences").Cells(Rows.Count, "F").End(xlUp).Row
Test1 = "CC"
Test2 = "TT"
Test3 = "GG"
For Row = FirstRow To LastRow
Sequence = ThisWorkbook.Sheets("Sequences").Cells(Row, Col).Value
For x = 1 To Len(Sequence)
SubSequence1 = Mid(Sequence, x, 2)
If SubSequence1 = Test1 Then
ThisWorkbook.Sheets("Sequences").Cells(Row, Col).Characters(x, 2).Font.Color = RGB(0, 0, 255)
ThisWorkbook.Sheets("Sequences").Cells(Row, Col).Characters(x, 2).Font.Bold = True
End If
If SubSequence1 = Test2 Then
ThisWorkbook.Sheets("Sequences").Cells(Row, Col).Characters(x, 2).Font.Color = RGB(0, 102, 0)
ThisWorkbook.Sheets("Sequences").Cells(Row, Col).Characters(x, 2).Font.Bold = True
End If
If SubSequence1 = Test3 Then
ThisWorkbook.Sheets("Sequences").Cells(Row, Col).Characters(x, 2).Font.Color = RGB(255, 153, 0)
ThisWorkbook.Sheets("Sequences").Cells(Row, Col).Characters(x, 2).Font.Bold = True
End If
Next x
Next Row
End Sub
だから、フィルタ値を言うとき、あなたはテーブルの実際のフィルタ検索ボックスについて話していません。あなたはテーブルにハイライト表示されている所定の文字列test1、test2、test3を持っていますか? – Carl