小编Ash*_*wad的帖子

使用 stringr 提取连字符后的前四位数字

我试图提取以下字符串中连字符后的前四位数字: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. 如何只提取四位数字而不提取连字符?

regex r

5
推荐指数
1
解决办法
1048
查看次数

使用 dplyr 语法在 duckdb 中生成确定性随机数

如何将 duckdb 的setseed()函数(请参阅参考文档)与 dplyr 语法一起使用,以确保下面的分析是可重现的?

\n
# 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)

r dplyr apache-arrow duckdb

5
推荐指数
1
解决办法
227
查看次数

Why does an `if statement` in R get evaluated without a logical condition?

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 …

r

2
推荐指数
1
解决办法
80
查看次数

标签 统计

r ×3

apache-arrow ×1

dplyr ×1

duckdb ×1

regex ×1