我想知道是否可以在R中使用testthat
测试框架来设置相等的容差.
目前,如果example.R
是:
library(testthat)
three_times<-function(x) 3*x
context('Test three_times')
test_that('Three times returns 3 times x',{
expect_equal(three_times(3),9)
expect_equal(three_times(pi),9.4247)
})
Run Code Online (Sandbox Code Playgroud)
并执行test_file('example.R','stop')
,第一次测试通过,但第二次测试失败:
Error: Test failed: 'Three times returns 3 times x'
Not expected: three_times(pi) not equal to 9.4247
Mean relative difference: 8.271963e-06.
Run Code Online (Sandbox Code Playgroud)
是否可以为平均相对差异设置更高的误差阈值?例如1e-3.我有一些只有3位小数精度的预期结果,这意味着现在我的测试总是失败...
我试图用指数衰减函数(RC类似系统)拟合数据:
我的数据位于以下数据框中:
dataset <- data.frame(Exp = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), t = c(0, 0.33, 0.67, 1, 1.33, 1.67, 2, 4, 6, 8, 10, 0, 33, 0.67, 1, 1.33, 1.67, 2, 4, 6, 8, 10, 0, 0.33, 0.67, 1, 1.33, 1.67, 2, 4, 6, 8, 10), fold = c(1, 0.957066345654286, 1.24139015724819, 1.62889151698633, …
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以使用ggplot2创建一个包含图像的多图(如facet):
我不知道如何安排图像数据传递给它们geom_raster()
或如何在数据框中包含图像......
我试过的:
> img1 <- readPNG('1.png')
> img2 <- readPNG('2.png')
> img3 <- readPNG('3.png')
> test <- data.frame(c(1,2,3),c(5,2,7),c(img1,img2,img3))
> nrow(test)
[1] 4343040
Run Code Online (Sandbox Code Playgroud)
我已经有了一个问题,建立一个内部图像的数据框...每3行重复一次(我想每像素一次).
只是一个警告,我一天前开始使用R ......如果有什么看似天真的简单,我道歉.
现在我试图让R接收一个带有影响的测量数据的.txt文件并计算它的头部伤害标准测试.HIC测试要求来自数据的曲线在特定间隔上进行积分.
等式在下面的链接...我试图在这里作为图像插入它但它不会让我.显然我需要一些声望点才能让我这样做.
a(t)是加速曲线.
到目前为止,我没有在R中生成合适的曲线以匹配数据的问题.黄土功能工作得很好,正是我正在寻找的东西...我只是不知道如何整合它.据我所知,黄土是一个非参数回归,所以没有办法确定它的曲线方程.有没有办法整合它呢?
如果没有,是否有另一种方法可以使用不同的功能来完成此任务?
任何帮助或有见识的评论将非常感谢.
提前致谢,
韦斯
詹姆斯还有一个问题,在使用integrate()函数时,如何才能获得没有文本和错误的数字?
我想从rmarkdown文件(使用RStudio)生成一个Gitlab风格的markdown(GFM),因此该文件可以在gitlab服务器上正确显示。
我特别希望乳胶配方能够正确显示。
在gitlab文档中指定公式应写在$`和`$之间
$`a^2+b^2=c^2`$
Run Code Online (Sandbox Code Playgroud)
但是Rmarkdown需要$ $ synthax(无`)
$a^2+b^2=c^2$
Run Code Online (Sandbox Code Playgroud)
目前,我已尝试在序言中使用以下yaml创建github式markdown:
output:
html_document:
keep_md: false
md_document:
variant: markdown_github
Run Code Online (Sandbox Code Playgroud)
但是在我的Rmd文件中输入以下内容时:
$A=\displaystyle\sum_{b} c_b$
Run Code Online (Sandbox Code Playgroud)
我在降价促销中得到以下信息:
*A*?=??<sub>*b*</sub>*c*<sub>*b*</sub>
Run Code Online (Sandbox Code Playgroud)
如何配置Rmarkdown或Rstudio,以便在md文件中获取此文件:
$`A=\displaystyle\sum_{b} c_b`$
Run Code Online (Sandbox Code Playgroud) 我正在创建一个 cookiecutter 模板,并且仅当变量具有给定值时才添加文件夹(及其包含的文件)。例如 cookiecutter.json:
\n{\n "project_slug":"project_folder"\n "i_want_this_folder":['y','n']\n}\n
Run Code Online (Sandbox Code Playgroud)\n我的模板结构如下所示:
\ntemplate\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 {{ cookiecutter.project_slug }}\n \xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 config.ini\n \xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 data\n \xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 data.csv\n \xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 {% if cookiecutter.i_want_this_folder == 'y' %}my_folder{% endif %}\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 some_files\n\n
Run Code Online (Sandbox Code Playgroud)\n但是,当运行cookiecutter template
并选择“n”时,我收到错误
Error: "~/project_folder" directory already exists\n
Run Code Online (Sandbox Code Playgroud)\n我的文件夹名称语法正确吗?
\n我有一个关于如何将fitdistr
计算的args 传递给的后续问题stat_function
(请参阅此处的上下文).
我的数据框是这样的(请参阅下面的完整数据集):
> str(small_data)
'data.frame': 1032 obs. of 3 variables:
$ Exp: Factor w/ 6 levels "1L","2L","3L",..: 1 1 1 1 1 1 1 1 1 1 ...
$ t : num 0 0 0 0 0 0 0 0 0 0 ...
$ int: num 75.7 86.1 76.3 82.3 98.3 ...
Run Code Online (Sandbox Code Playgroud)
我想绘制一个facet_grid分组Exp
并t
显示密度直方图,int
并绘制拟合的对数正态分布(由t着色的对数正态线).我尝试过以下方法:
library(MASS)
meanlog <- function(x) { fitdistr(x,"lognormal")$estimate[[1]] }
sdlog <- function(x) { fitdistr(x,"lognormal")$estimate[[2]] }
p_chip<- …
Run Code Online (Sandbox Code Playgroud) 我有一个R markdown文件:
---
title: "Untitled"
author: "Me"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document.
Run Code Online (Sandbox Code Playgroud)
以及DiagrammeR /美人鱼图表:
graph LR
A-->B
Run Code Online (Sandbox Code Playgroud)
如何在R-markdown中添加图表?
r ×7
ggplot2 ×3
r-markdown ×2
cookiecutter ×1
diagrammer ×1
facet ×1
gitlab ×1
mermaid ×1
python ×1
testthat ×1
unit-testing ×1