0

agrepに一致secondsさせようとしてsecondいますが、これを達成するための値はない millisecondようです。costs

deletions/のコストの価値がないことは特に混乱していinsertionsます。これはトリックを行うようです-私が見るように、second削除は 1 回ですが、seconds削除millisecondは 1 回で、挿入は 5 回です。

(しばらく時間がかかる場合があることを警告しlapplyます...同じ結果が得られlength.out = 100:10はるかに速くなります)

rng = c(seq(0, 1, length.out = 20), 0:100)
x = expand.grid(insertions = rng, substitutions = rng, deletions = rng)

units = c("millisecond", "second", "minute", "hour", "day",
          "week", "month", "quarter", "year")
x$match = lapply(seq_len(nrow(x)), function(ii)
  agrep('second', units, value = TRUE, costs = x[ii, ]))

x$match_which = sapply(x$match, paste, collapse = '|')

sort(table(x$match_which))
#             millisecond|second|minute|hour|week|month|year 
#                                                         57 
#     millisecond|second|minute|hour|week|month|quarter|year 
#                                                      13276 
#                                   millisecond|second|month 
#                                                      23316 
#                    millisecond|second|minute|month|quarter 
#                                                      37842 
#                          millisecond|second|minute|quarter 
#                                                     251480 
# millisecond|second|minute|hour|day|week|month|quarter|year 
#                                                     409865 
#                                         millisecond|second 
#                                                    1035725 

ここで何が欠けていますか?で私のタスクを達成する方法はありませんか ( と一致secondssecondないmillisecond) agrep?

4

0 に答える 0