2017-09-29 4 views

答えて

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 
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 
) 
1

私はこのような何かを示唆している:

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 
+0

を、それが正常に動作している.....ありがとう...... – vinodetrx

関連する問題