ID EN
String Functions

agrep

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Mencari perkiraan kecocokan dengan pola (argumen pertama) dalam setiap elemen string x (argumen kedua) menggunakan jarak edit Levenshtein yang digeneralisasi (jumlah minimal penyisipan, penghapusan, dan substitusi yang mungkin berbobot yang diperlukan untuk mengubah satu string menjadi string lainnya).

Syntax

R
agrep(pattern, x, max.distance = 0.1, costs = NULL,
      ignore.case = FALSE, value = FALSE, fixed = TRUE,
      useBytes = FALSE)<p></p><p>agrepl(pattern, x, max.distance = 0.1, costs = NULL,
       ignore.case = FALSE, fixed = TRUE, useBytes = FALSE)</p>

Arguments

Parameter Deskripsi
pattern a non-empty character string or a character string containing a regular expression (for fixed = FALSE) to be matched. Coerced by as.character to a string if possible.
x character vector where matches are sought. Coerced by as.character to a character vector if possible.
max.distance Maximum distance allowed for a match. Expressed either as integer, or as a fraction of the pattern length times the maximal transformation cost (will be replaced by the smallest integer not less than the corresponding fraction), or a list with possible components cost:maximum number/fraction of match cost (generalized Levenshtein distance) all:maximal number/fraction of all transformations (insertions, deletions and substitutions) insertions:maximum number/fraction of insertions deletions:maximum number/fraction of deletions substitutions:maximum number/fraction of substitutions If cost is not given, all defaults to 10%, and the other transformation number bounds default to all. The component names can be abbreviated.
costs a numeric vector or list with names partially matching insertions, deletions and substitutions giving the respective costs for computing the generalized Levenshtein distance, or NULL (default) indicating using unit cost for all three possible transformations. Coerced to integer via as.integer if possible.
ignore.case if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.
value if FALSE, a vector containing the (integer) indices of the matches determined is returned and if TRUE, a vector containing the matching elements themselves is returned.
fixed logical. If TRUE (default), the pattern is matched literally (as is). Otherwise, it is matched as a regular expression.
useBytes logical. in a multibyte locale, should the comparison be character-by-character (the default) or byte-by-byte.

Return Value

agrep mengembalikan vektor yang memberikan indeks elemen yang menghasilkan kecocokan, atau, jika nilainya TRUE, elemen yang cocok (setelah paksaan, mempertahankan nama tetapi tidak ada atribut lainnya). agrepl mengembalikan vektor logis.

Details

Jarak edit Levenshtein digunakan sebagai ukuran perkiraan: ini adalah jumlah total penyisipan, penghapusan, dan penggantian (mungkin tertimbang biaya) yang diperlukan untuk mengubah satu string menjadi string lainnya. Ini menggunakan tre oleh Ville Laurikari (http://laurikari.net/tre/), yang mendukung pencocokan karakter MBCS. Efek utama useBytes adalah untuk menghindari kesalahan/peringatan tentang input yang tidak valid dan kecocokan palsu di lokal multibyte. Ini menghambat konversi input dengan pengkodean yang ditandai, dan dipaksakan jika ada input yang ditandai sebagai "byte" ditemukan (lihat Pengkodean).

Contoh

Example
R
# NOT RUN {
agrep("lasy", "1 lazy 2")
agrep("lasy", c(" 1 lazy 2", "1 lasy 2"), max = list(sub = 0))
agrep("laysy", c("1 lazy", "1", "1 LAZY"), max = 2)
agrep("laysy", c("1 lazy", "1", "1 LAZY"), max = 2, value = TRUE)
agrep("laysy", c("1 lazy", "1", "1 LAZY"), max = 2, ignore.case = TRUE)
# }

See Also

grep adist. A different interface to approximate string matching is provided by aregexec().