请考虑以下代码:
foo <- function() {
if (runif(1) < 0.5) {
return(data.frame(result="low"))
} else {
return(data.frame(result="high"))
}
}
df = data.frame(val=c(1,2,3,4,5,6))
df %>% group_by(val) %>% do(foo())
Run Code Online (Sandbox Code Playgroud)
它是随机的,但如果同时返回"低"和"高"结果,您将看到如下错误:
Warning messages:
1: In bind_rows_(x, .id) : Unequal factor levels: coercing to character
2: In bind_rows_(x, .id) :
binding character and factor vector, coercing into character vector
3: In bind_rows_(x, .id) :
binding character and factor vector, coercing into character vector
4: In bind_rows_(x, .id) :
binding character and factor vector, coercing into character …Run Code Online (Sandbox Code Playgroud) 有没有办法从Markdown(.md)文件创建包装插图,而不是Rmarkdown(.Rmd)或任何其他类型?
我发现了另一个问题,但它是关于生成/保持输入的.md输出.Rmd,而我想从输入开始.md.
我有一堆使用 Azure Pipelines 进行 CI/CD 的存储库,我现在正在尝试将其移植到 Github Actions。这是我正在研究的第一个:https://github.com/Azure/AzureAuth/tree/fix-ghaction
我已经完成了 99% 的工作,但在某一步骤中我遇到了奇怪的身份验证错误。该存储库已镜像到另一个组织(cloudyr),我使用此步骤进行镜像:
- name: Copy to Cloudyr
if: runner.os == 'Linux'
env:
token: "${{ secrets.ghPat }}"
run: |
export CLOUDYR_REPO=$(echo $GITHUB_REPOSITORY | sed "s/Azure/cloudyr/")
git push --prune https://$token@github.com/${CLOUDYR_REPO}.git +refs/remotes/origin/*:refs/heads/* +refs/tags/*:refs/tags/*
Run Code Online (Sandbox Code Playgroud)
这会从存储库机密中检索 PAT,并执行git push. 它与 Azure Pipelines 完美配合,但现在失败并出现以下错误:
Run export CLOUDYR_REPO=$(echo $GITHUB_REPOSITORY | sed "s/Azure/cloudyr/")
remote: Permission to cloudyr/AzureAuth.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/cloudyr/AzureAuth.git/': The requested URL returned error: 403
Error: Process completed with exit code …Run Code Online (Sandbox Code Playgroud) 通过选择最大值将多个变量合并为一个
id v1 v2 v3 v4 v5 v6
1 1 2 5 3 1 1
2 4 2 3 5 1
3 3 2 2 1 3
4 2 1 2 5 7
5 6 7 1 2 1 7
Run Code Online (Sandbox Code Playgroud)
进入 n1=max(v1,v2),n2=v3,n3=max(v4,v5,v6)
id n1 n2 n3
1 2 5 3
2 4 3 5
3 3 2 3
4 2 2 7
5 7 1 7
Run Code Online (Sandbox Code Playgroud)
我如何在 SAS 中执行此操作?(在 excel 中很容易。在 R 中相对直观。但我在 SAS 中无法弄清楚!请帮忙!)
感谢您的时间!
我有一个包含5行样本数据的Excel文件.我已经给出以下代码将其导入R.
> testdata <-read.table(file.choose(),header=TRUE)
Run Code Online (Sandbox Code Playgroud)
我收到如下警告信息.
Warning message:
In read.table(file.choose(), header = TRUE) :
incomplete final line found by readTableHeader on
Run Code Online (Sandbox Code Playgroud)
我忽略了警告消息并继续查看我的数据,但发现没有选择任何行.以下是我到达的内容
> testdata
[1] PK...
<0 rows> (or 0-length row.names)
Run Code Online (Sandbox Code Playgroud)
由于我是RI的初学者,因此无法追踪错误.任何关于警告和错误的帮助将不胜感激.请帮忙.
所以我有这个看起来像这样的情节:

x轴和y轴都是log,我如何拟合最小二乘回归线?这是我用来绘制图形的图:plot(log(counts),log ="x",type ="p")
count包含每个x的观察数...
我是R的新手我正在使用R 3.0.1版本,我已经使用install.packages("rpart")在弹出框中选择了美国(CA 1)安装了rpart包,它已成功安装
> p_data = read.csv(file="/home/sudeep/Desktop/mysql.tsv",sep="\t",dec=".",header=TRUE)
> dtree <- rpart(paid ~ .,data = p_data, method="class")
Error: could not find function "rpart"
Run Code Online (Sandbox Code Playgroud)
那我怎么了?
帮助approx并approxfun包括以下警告:
警告
由roxfun返回的值包含对当前R版本中代码的引用:不应将其保存并加载到其他R会话中。对于R> = 3.0.0,这更安全。
我不确定这意味着什么,尤其是关于“对于R> = 3.0.0更安全”的最后一部分。我已经编写了一些代码,其中包含使用创建的函数approxfun。现在将该代码放入包中是否安全?我已经对其进行了测试,并且似乎可以运行,但是我不知道我是否可以依靠它。
这是Windows 7 64位上的R 3.1.1。
确切的代码是这样的。我有一些关于函数值的数据,并且我想近似底层函数(我没有源代码)。
.table <- read.table(text="x y
10.0 150
37.8 147
65.6 145
93.3 142", header=TRUE) # plus several more lines in the original
# this function is to be exported in the package
f <- with(.table, approxfun(x, y))
Run Code Online (Sandbox Code Playgroud)
.approxfun是stats包中的未导出函数。因此,R的未来版本可能会忽略此功能,尽管至少在短期内这不太可能。但是还有另一个问题。我仔细查看了的来源approxfun,并以以下几行结尾:
....
x <- as.double(x)
y <- as.double(y)
.Call(C_ApproxTest, x, y, method, f)
function(v) .approxfun(x, y, v, method, yleft, yright, f) …Run Code Online (Sandbox Code Playgroud) 我想进行逻辑回归:我有1个因变量和~10个预测变量.
我想在尝试每种组合时执行详尽的搜索,例如更改顺序和添加/删除预测变量等.例如:
y~x1 + x2 + x3 + x4 + x5
y~x2 + x1 + x3 + x4 + x5
y~x1 + x2 + x3
y~x5 + x1 + x2 + x3 + x4
y~x4 + x2
...等等.
在这种情况下,计算时间对我来说不是一个停止的问题:这主要是一项教育活动.
你知道我该怎么做吗?我用R.
编辑:要明确:这主要是一个教育练习:我想测试每个模型,所以我可以根据一些索引(如AUC或伪R²)对它们进行排序,以便向我的" 学生 "展示哪些预测器似乎有趣但没有科学意义.我打算执行bootstrap重采样以进一步测试"最狂野 "的模型.
使用R 3.2.2和dplyr 0.7.2我试图弄清楚如何有效地使用group_by作为字符向量提供的字段。
选择很容易我可以通过这样的字符串选择一个字段
(function(field) {
mpg %>% dplyr::select(field)
})("cyl")
Run Code Online (Sandbox Code Playgroud)
通过像这样的多个字符串的多个字段
(function(...) {
mpg %>% dplyr::select(!!!quos(...))
})("cyl", "hwy")
Run Code Online (Sandbox Code Playgroud)
和多个字段,通过一个长度 > 1 的字符向量,像这样
(function(fields) {
mpg %>% dplyr::select(fields)
})(c("cyl", "hwy"))
Run Code Online (Sandbox Code Playgroud)
随着group_by我真的不能找到一种方法,因为如果我设法得到一个输出它结束了由字符串我供应分组为多个字符串做到这一点。
我设法按这样的一个字符串分组
(function(field) {
mpg %>% group_by(!!field := .data[[field]]) %>% tally()
})("cyl")
Run Code Online (Sandbox Code Playgroud)
这已经很丑了。
有谁知道我必须写什么,以便我可以运行
(function(field) {...})("cyl", "hwy")
Run Code Online (Sandbox Code Playgroud)
和
(function(field) {...})(c("cyl", "hwy"))
Run Code Online (Sandbox Code Playgroud)
分别?我试过各种组合!!,!!!,UQ,enquo,quos,unlist,等...,并将其保存在中间变量,因为,有时似乎有所作为,但它不能去工作。