I tried this but this will again required a for-loop to compare so any better method to find the index.
str[[1]][1]
"NYA.FWD.AMGM.MON..MAXRUNALARM."
m<-grep( str[[1]][1] , colnames(log_data)[2:ncol(log_data)] , value=FALSE)
m
[1] 5 6
where
colnames(log_data)[6]
"NYA.FWD.AMGM.MON..MAXRUNALARM....SU."
colnames(log_data)[7]
"NYA.FWD.AMGM.MON..MAXRUNALARM."
I only want the 6 as indices ,means the exact length of the string or is there an better method to extract the similar string of same length.
I also used
str_detect((colnames(log_data)[2:ncol(log_data)]),fixed(str[[1]][1]))
[1] FALSE FALSE FALSE FALSE **TRUE TRUE** FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
but getting the logical vectors just want a single index ,thank you.
If you want an exact match, use
match:It will return the index of the first match. If you have multiple matches and want all their indices, do: