谁能解释一下 R 中的波浪号 (~.)?我已经看到一些关于它的帖子。我知道波浪号用于公式,指定自变量和因变量。而且,我知道点用于表示所有其他变量。更具体地说,有人可以解释这个例子中的波浪号吗?
x <- sample(10)
x %>%
detect(~. > 5)
Run Code Online (Sandbox Code Playgroud)
谢谢
这是我的数据:
\ndat <- mtcars\ndat$Brands <- rownames(dat)\ndat$Info <- rep("Info", length(rownames(mtcars)))\nRun Code Online (Sandbox Code Playgroud)\n我已经看到有很多方法可以对整个数据框架执行某些操作。mutate,sapply等等。但是,对于某些特定功能它不起作用。
最接近的例子是如果你想做的话log2+1。
我已经尝试过这个...
\ndata_log <- dat %>% mutate(across(where(is.numeric), log2+1))\nRun Code Online (Sandbox Code Playgroud)\n但这给了我这个错误......
\n\n\n错误:
\nmutate()输入有问题..1。\n\xe2\x84\xb9..1 = across(where(is.numeric), log2 + 1)。\nx 二元运算符的非数字参数\n运行rlang::last_error()以查看发生错误的位置。
您知道是否有办法运行此类功能?
\n