Given a string of letters, we need to split them in half, and then find the single letter in common between them. Each letter is assigned a score, and then we need to sum them up.
I think I’ll rely on stringr for this?
sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.3
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices datasets utils methods base
loaded via a namespace (and not attached):
[1] digest_0.6.30 jsonlite_1.8.3 magrittr_2.0.3 evaluate_0.17
[5] rlang_1.0.6 stringi_1.7.8 cli_3.4.1 renv_0.15.5
[9] rstudioapi_0.14 rmarkdown_2.17 tools_4.2.1 stringr_1.4.1
[13] htmlwidgets_1.5.4 xfun_0.34 yaml_2.3.6 fastmap_1.1.0
[17] compiler_4.2.1 htmltools_0.5.3 knitr_1.40
Rows: 300 Columns: 1
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (1): X1
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
compartment <- input |>mutate(# Get a total character countn =nchar(X1),# split the whole character string into a listitem_list =map(X1, ~str_split(.x, pattern ="", simplify =TRUE)),# get the vector for the first halfcompartment1 =map2(item_list, n, ~.x[1:(.y/2)]),# get the vector for the second halfcompartment2 =map2(item_list, n, ~.x[((.y/2)+1):.y]),# get the shared valuesshared =map2(compartment1, compartment2, ~.x[.x %in% .y]) )
At this point, there are some values in shared are longer than 1. I need to check on those