rのデータフレーム全体で 'IDP' & 'SB'を含むテキストの行と列のインデックスを抽出します。正規表現を使用してデータフレーム内のテキストの行と列を抽出する方法
テキストパターンは、私の出力は、
row column
1 1
2 1
rのデータフレーム全体で 'IDP' & 'SB'を含むテキストの行と列のインデックスを抽出します。正規表現を使用してデータフレーム内のテキストの行と列を抽出する方法
テキストパターンは、私の出力は、
row column
1 1
2 1
一つのオプションは、列をループになることがgrepl
を使用して、which
とし、arr.ind = TRUE
インデックスを取得します
Col1 Col2
IDP ENGINE(SB) IDP ENGINE(PS)
IDP ENGINE SB01 MAIN ENGINE(SB)
IDP ENGINE SDV AUX. ENGINE(SB)
次のようになります
which(sapply(df1, function(x) grepl("(\\bIDP\\b.*\\bSB)|(\\bSB\\bIDP)", x)), arr.ind = TRUE)
# row col
#[1,] 1 1
#[2,] 2 1
d = data.frame(
col1 = c("IDP ENGINE(SB)", "IDP ENGINE SB01", "IDP ENGINE SDV")
, col2 = c("IDP ENGINE(PS)", "MAIN ENGINE(SB)", "AUX. ENGINE(SB)")
);
d
which(
apply(d, c(1,2), grepl, pattern="IDP") & apply(d, c(1,2), grepl, pattern="SB")
, arr.ind = TRUE
)
私はこのような何かを示唆している:
which(matrix(grepl(pattern = '(?=.*IDP)(?=.*SB)', as.matrix(df1), perl = TRUE), ncol = NCOL(df1)), arr.ind = TRUE)
row col [1,] 1 1 [2,] 2 1
を、それが正常に動作している.....ありがとう...... – vinodetrx