我试图提取以下字符串中连字符后的前四位数字:extract_public_2018_20190530180949469_58906_20110101-20111231Texas
。我正在使用以下代码:
stringr::str_extract(
"extract_public_2018_20190530180949469_58906_20110101-20111231Texas",
"-[[:digit:]]{4}"
)
Run Code Online (Sandbox Code Playgroud)
但我得到的-2011
不是2011
. 如何只提取四位数字而不提取连字符?
如何将 duckdb 的setseed()
函数(请参阅参考文档)与 dplyr 语法一起使用,以确保下面的分析是可重现的?
# dplyr version 1.1.1\n# arrow version 11.0.0.3\n# duckdb 0.7.1.1\nout_dir <- tempfile()\narrow::write_dataset(mtcars, out_dir, partitioning = "cyl")\n\nmtcars_ds <- arrow::open_dataset(out_dir)\n\nmtcars_smry <- mtcars_ds |>\n arrow::to_duckdb() |>\n dplyr::mutate(\n fold = ceiling(3 * random())\n ) |>\n dplyr::summarize(\n avg_hp = mean(hp),\n .by = c(cyl, fold)\n )\n\nmtcars_smry |>\n dplyr::collect()\n#> Warning: Missing values are always removed in SQL aggregation functions.\n#> Use `na.rm = TRUE` to silence this warning\n#> This warning is displayed once every 8 hours.\n#> # A tibble: …
Run Code Online (Sandbox Code Playgroud) I noticed that if I pass any number except 0 as an argument to an if statement
, the code inside the if statement
compiles. I am confused why this is happening! I understand that R internally recognizes 0 as FALSE and the statement inside the if condition
is not evaluated, which makes sense, but why is it getting evaluated for other numbers?
if(5) {
5 * 5
}
Run Code Online (Sandbox Code Playgroud)
I had expected that I will get an error, but the …