Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Richard O'Keefe
This seems unnecessarily complex. Or rather, it pushes the complexity into an arcane notation What we really want is something that says "here is a string, here is a pattern, give me all the substrings that match." What we're given is a function that tells us where those substrings are. #

Re: [R] Fwd: r-stats: Geometric Distribution

2023-10-18 Thread Jim Lemon
Please delete drjimle...@gmail.com from your mailing lists. He passed away a mknth ago. Regards, Juel Wife On Tue, 17 Oct 2023, 22:58 Sahil Sharma -- Forwarded message - > From: Sahil Sharma > Date: Tue, Oct 17, 2023 at 12:10 PM > Subject: r-stats: Geometric Distribution > To:

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Jim Lemon
Please delete drjimle...@bitwrit.com from your mailing list. He passed away a month ago. Regards, Juel (wife) On Thu, 19 Oct 2023, 02:09 Ben Bolker There are some answers on Stack Overflow: > > >

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Ivan Krylov
The matching approach is also competitive: match.symbol2 <- function(x, rm.digits = TRUE) { if (rm.digits) stringi::stri_extract_all(x, regex = '[A-Z][a-z]*') else lapply( stringi::stri_match_all(x, regex = '([A-Z][a-z]*)([0-9]*)'), \(m) { m <- t(m[,2:3]); m[nzchar(m)] } ) } mol5 <-

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Rui Barradas
Às 19:35 de 18/10/2023, Leonard Mada escreveu: Dear Rui, On 10/18/2023 8:45 PM, Rui Barradas wrote: split_chem_elements <- function(x, rm.digits = TRUE) {   regex <- "(?<=[A-Z])(?![a-z]|$)|(?<=.)(?=[A-Z])|(?<=[a-z])(?=[^a-z])"   if(rm.digits) {     stringr::str_replace_all(mol, regex, "#") |>  

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Leonard Mada via R-help
Dear Rui, On 10/18/2023 8:45 PM, Rui Barradas wrote: split_chem_elements <- function(x, rm.digits = TRUE) {   regex <- "(?<=[A-Z])(?![a-z]|$)|(?<=.)(?=[A-Z])|(?<=[a-z])(?=[^a-z])"   if(rm.digits) {     stringr::str_replace_all(mol, regex, "#") |>   strsplit("#|[[:digit:]]") |>  

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Rui Barradas
Às 17:24 de 18/10/2023, Leonard Mada escreveu: Dear Rui, Thank you for your reply. I do have actually access to the chemical symbols: I have started to refactor and enhance the Rpdb package, see Rpdb::elements: https://github.com/discoleo/Rpdb However, the regex that you have constructed is

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread avi.e.gross
Rui, The problem with searching for elements, as with many kinds of text, is that the optimal search order may depend on the probabilities of what is involved. There can be more elements added such as Unobtainium in the future with whatever abbreviations that may then change the algorithm you

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Leonard Mada via R-help
Dear Rui, Thank you for your reply. I do have actually access to the chemical symbols: I have started to refactor and enhance the Rpdb package, see Rpdb::elements: https://github.com/discoleo/Rpdb However, the regex that you have constructed is quite heavy, as it needs to iterate through

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Rui Barradas
Às 15:59 de 18/10/2023, Leonard Mada via R-help escreveu: Dear List members, What is the best way to test for numeric digits? suppressWarnings(as.double(c("Li", "Na", "K",  "2", "Rb", "Ca", "3"))) # [1] NA NA NA  2 NA NA  3 The above requires the use of the suppressWarnings function. Are there

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Ivan Krylov
В Wed, 18 Oct 2023 17:59:01 +0300 Leonard Mada via R-help пишет: > What is the best way to test for numeric digits? > > suppressWarnings(as.double(c("Li", "Na", "K",  "2", "Rb", "Ca", "3"))) > # [1] NA NA NA  2 NA NA  3 > The above requires the use of the suppressWarnings function. Are > there

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Jeff Newmiller via R-help
Use any occurrence of one or more digits as a separator? s <- c( "CCl3F", "Li4Al4H16", "CCl2CO2AlPO4SiO4Cl" ) strsplit( s, "\\d+" ) On October 18, 2023 7:59:01 AM PDT, Leonard Mada via R-help wrote: >Dear List members, > >What is the best way to test for numeric digits? >

Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Ben Bolker
There are some answers on Stack Overflow: https://stackoverflow.com/questions/14984989/how-to-avoid-warning-when-introducing-nas-by-coercion On 2023-10-18 10:59 a.m., Leonard Mada via R-help wrote: Dear List members, What is the best way to test for numeric digits?

[R] Best way to test for numeric digits?

2023-10-18 Thread Leonard Mada via R-help
Dear List members, What is the best way to test for numeric digits? suppressWarnings(as.double(c("Li", "Na", "K",  "2", "Rb", "Ca", "3"))) # [1] NA NA NA  2 NA NA  3 The above requires the use of the suppressWarnings function. Are there any better ways? I was working to extract chemical