"
> orig[!elements_bool]
[1] "2" "3"
Other approaches you might consider depending on your needs is to encapsulate
your data as a column in a data.frame or tibble or other such construct and
generate additional columns along the way that keep your information
con
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.
#
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:
>
>
>
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 <-
À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, "#") |>
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:]]") |>
À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
-help
Sent: Wednesday, October 18, 2023 12:24 PM
To: Rui Barradas ; R-help Mailing List
Subject: Re: [R] Best way to test for numeric digits?
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
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
À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
В 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
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?
>
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?
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
14 matches
Mail list logo