我对 感兴趣?typeof,它提到了可以返回的值。有没有办法打电话typeof(something)并获得以下其中一项?
“承诺”、“字符”、“...”、“任何”、“字节码”
我发现我可以获得两种更奇特的类型,帮助认为typeof“不太可能在用户级别看到”,如下所示:
typeof(new("externalptr"))
# [1] "externalptr"
typeof(rlang::new_weakref(new("externalptr")))
# [1] "weakref"
Run Code Online (Sandbox Code Playgroud)
但有办法得到其他人吗?
当我使用时,为什么拆分公式不会扩展到整个列=arrayformula(split(input!G2:G, ","))?
我得到的结果只是输入!G2单元格,而不是G列中的其余单元格.其他公式=arrayformula(find(",", input!G2:G))似乎功能和扩展没有问题.
如果提供的不是数字,+通常会抛出non-numeric argument to binary operator.但它适用于ggplot2,将情节粘贴在一起.同时,它在ggplot2的上下文之外保留其常用功能(例如,作为算术运算符或公式运算符),因此其ggplot2版本与这两者中的任何一个都不冲突.
我希望了解如何以+这种方式表现.浏览ggplot2 github repo,我找到了函数定义+.gg,%+%但它并没有让我更清楚.
我会很高兴指向ggplot2包中执行此操作的代码,或者对如何完成此操作的一般化解释.
给定此示例 yaml,代码折叠按钮呈现在右侧:
---
title: "Some Title"
output:
html_document:
code_folding: hide
theme: united
---
Run Code Online (Sandbox Code Playgroud)
这看起来对我没有吸引力,我希望它们在左边。目前,我将此覆盖包含在 .Rmd 文档的正文中:
```{css, echo=FALSE}
/* Move code folding buttons to the left */
div.col-md-12 .pull-right {
float: left !important
}
```
Run Code Online (Sandbox Code Playgroud)
这可行,但感觉有点脏。另外,很难预测它与未来文档中可能使用的其他一些元素结合起来可能会造成什么混乱。
在 RMarkdown 中是否有“正确”的方法来自定义它?
以下代码
library(ggplot2)
library(reshape2)
m=melt(iris[,1:4])
ggplot(m, aes(value)) +
facet_wrap(~variable,ncol=2,scales="free_x") +
geom_histogram()
Run Code Online (Sandbox Code Playgroud)
产生4个固定y轴的图形(这就是我想要的).但是,默认情况下,y轴仅显示在刻面图的左侧(即第1和第3图的侧面).
如何使y轴在所有4个图形上显示?谢谢!
编辑:正如@Roland所建议的,可以设置scales="free"和使用ylim(c(0,30)),但我不希望每次都手动设置限制.
@Roland还建议使用hist和ddply外界ggplot的,以获得最大数量.没有任何ggplot2基础解决方案吗?
编辑: @babptiste有一个非常优雅的解决方案.但是,当更改binwidth时,它开始表现得很奇怪(至少对我而言).使用默认binwidth(范围/ 30)检查此示例.y轴上的值介于0到30,000之间.
library(ggplot2)
library(reshape2)
m=melt(data=diamonds[,c("x","y","z")])
ggplot(m,aes(x=value)) +
facet_wrap(~variable,ncol=2,scales="free") +
geom_histogram() +
geom_blank(aes(y=max(..count..)), stat="bin")
Run Code Online (Sandbox Code Playgroud)

而现在这一个.
ggplot(m,aes(x=value)) +
facet_wrap(~variable,scales="free") +
geom_histogram(binwidth=0.5) +
geom_blank(aes(y=max(..count..)), stat="bin")
Run Code Online (Sandbox Code Playgroud)

binwidth现在设置为0.5,因此最高频率应该改变(实际上减少,因为在更紧密的箱中会有更少的观测值).但是,y轴没有发生任何变化,它仍然覆盖相同数量的值,在每个图形中创建了一个巨大的空白空间.
[问题解决了......请参阅@ baptiste编辑的答案.]
在 Google 表格中,我将其放在一个单元格中:
Random stuff blah blah 123456789
<Surname, Name><123456><A><100><B><200>
<Surname2, Name2><456789><A><300><B><400>
Some more random stuff
Run Code Online (Sandbox Code Playgroud)
并想匹配<>括号内的字符串。到目前为止= REGEXEXTRACT(A4, "<(.*)>")我得到了:
Surname, Name><123456><A><100><B><200
Run Code Online (Sandbox Code Playgroud)
这很好,但这只是第一行。所需的输出将是这样的(也许包括<>开头/结尾,这并不重要):
Surname, Name><123456><A><100><B><200>
<Surname2, Name2><456789><A><300><B><400
Run Code Online (Sandbox Code Playgroud)
或者简单地:
Surname, Name><123456><A><100><B><200><Surname2, Name2><456789><A><300><B><400
Run Code Online (Sandbox Code Playgroud)
到那里怎么走?
R中是否有弃用参数的标准方法?
示例:对于Web API程序包,我之前包含了一个paging=TRUE参数,它将对所有结果进行分页并下载所有内容。
现在,我想使用一个limit参数,如果设置为,则仅下载所有内容limit=0。这有效地消除了对paging参数的需求,因此,我现在需要让人们现在基本上不执行任何操作。我怎么做?
假设我想像这样操作函数体:
> f1 = function(a, b, d) {
+ stop("This is a template!")
+ result
+ }
> body(f1)[[2]] = call("<-", as.name("result"), lapply(letters[1:2], as.name))
Run Code Online (Sandbox Code Playgroud)
这看起来不错...
> f1
function (a, b, d)
{
result <- list(a, b)
result
}
Run Code Online (Sandbox Code Playgroud)
...但不起作用:
> f1(a = 123, b = 456, d = 999)
[[1]]
a
[[2]]
b
Run Code Online (Sandbox Code Playgroud)
另一方面,当我这样做时:
> body(f1)[[2]] = call("<-", as.name("result"),
+ as.call(c(as.name("list"), lapply(letters[1:2], as.name))))
Run Code Online (Sandbox Code Playgroud)
它看起来同...
> f1
function (a, b, d)
{
result <- list(a, b)
result …Run Code Online (Sandbox Code Playgroud) 我正在尝试连接到远程可公开访问的MySQL服务器EnsEMBL公共服务器RMySQL,但是当我尝试列出表时,会发生错误:
library(RMySQL)
mydb = dbConnect(MySQL(),
user = 'anonymous',
port = 5306,
host = 'asiadb.ensembl.org')
dbListTables(mydb)
Error in .local(conn, statement, ...) :
could not run statement: No database selected
Run Code Online (Sandbox Code Playgroud)
有没有办法找出这个名字?或者我是否完全犯了一个完全不同的错误?
r ×7
ggplot2 ×2
css ×1
lookup ×1
operators ×1
r-markdown ×1
regex ×1
rmysql ×1
split ×1
substitution ×1