在R降价文档(html和演示文稿)中,是否可以手动将标题拆分为多行?我试着玩管道产生orrendous输出.
---
title: 'A title I want to split on two lines'
author:
date:
output:
ioslides_presentation
---
Run Code Online (Sandbox Code Playgroud) 我正在尝试解决R中的数据管理问题.
假设我的数据如下:
id <- c("123", "414", "606")
next.up <- c("414", "606", "119")
is.cond.met <- as.factor(c("FALSE", "FALSE", "TRUE"))
df <- data.frame(id, next.up, is.cond.met)
> df
id next.up is.cond.met
1 123 414 FALSE
2 414 606 FALSE
3 606 119 TRUE
Run Code Online (Sandbox Code Playgroud)
我想获得的是以下内容:
id <- c("123", "414", "606")
next.up <- c("414", "606", "119")
is.cond.met <- as.factor(c("FALSE", "FALSE", "TRUE"))
origin <- c("606", "606", "119")
df.result <- data.frame(id, next.up, is.cond.met, origin)
> df.result
id next.up is.cond.met origin
1 123 414 FALSE 606
2 414 606 …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种有效的方法来识别时间序列中的咒语/奔跑。在下图中,前三列是我所拥有的,第四列spell是我要计算的。我已经尝试使用dplyr的lead和lag,但过于复杂。我已经尝试过,rle但无处可去。
代表
df <- structure(list(time = structure(c(1538876340, 1538876400,
1538876460,1538876520, 1538876580, 1538876640, 1538876700, 1538876760, 1526824800,
1526824860, 1526824920, 1526824980, 1526825040, 1526825100), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), group = c("A", "A", "A", "A", "A", "A", "A", "A", "B",
"B", "B", "B", "B", "B"), is.5 = c(0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1)),
class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -14L))
Run Code Online (Sandbox Code Playgroud)
我更喜欢一个tidyverse解决方案。 …
我使用(新的)RStudio 四开引擎创建了一个 Markdown。我想将 .md 上传到 Github 存储库中。然而,很少有元素能够正确渲染。例如,许多表格不渲染,一些 Markdown 代码按原样渲染(例如:::{.column-page})。
这是我第一次使用四开本。如果我想创建一个尽可能与 Github markdown 引擎兼容的 r markdown,我应该做什么(我不必坚持使用四开)?
在 xaringan 中,我想在标题幻灯片中添加背景。我已经按照一辉的指示做到了。
这有效,除了我松开了默认字体 (Yanone Kaffeesatz)。
YAML:
---
title: "My title"
subtitle: "My subtitle"
author: "Me Myself"
date: "01/01/2012"
output:
xaringan::moon_reader:
css: my-theme.css
lib_dir: libs
nature:
ratio: '16:9'
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
Run Code Online (Sandbox Code Playgroud)
其中my-theme.css如下:
.title-slide {
background-image: url(Figures/MyBackground.jpg);
background-size: cover;
}
Run Code Online (Sandbox Code Playgroud) 我正在寻找在不损失分辨率的情况下为长时间序列图制作动画的方法。我希望视图在数据之间“平移”,以显示从头到尾的滑动子集。
假设我有以下内容:
library(ggplot2)
library(dplyr)
library(gganimate)
df <- as.data.frame(cumsum(rnorm(1:10000))) %>% rename(y = 1)
df <- mutate(df, seq = seq(1, 10000, by = 1))
ggplot(df, aes(x = seq, y = y)) +
geom_line()
Run Code Online (Sandbox Code Playgroud)
我想创建一个动画来显示更多细节,方法是一次只关注数据的一部分,然后从头到尾滑动。想象一下通过放大镜放大该系列,同时在下方滑动图...这就是我要达到的效果。有可能通过gganimate吗?如果没有,有什么建议吗?
pivot_longer我在使用on 变量块时遇到问题。假设我有这个:
我想要这个:
dfwide <- structure(list(date = structure(c(1577836800, 1577923200, 1578009600,
1578096000, 1578182400, 1578268800), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), x1_a = c(20, 15, 12, NA, 25, 27), x1_b = c(33,
44, 85, 10, 12, 3), x1_c = c(70, 20, 87, 11, 20, 5), x2_a = c(85,
65, 33, 46, 82, 9), x2_b = c(87, 25, 55, 64, 98, 5), x2_c = c(77,
51, 92, 20, 37, 98)), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
Run Code Online (Sandbox Code Playgroud)
##Tried: …Run Code Online (Sandbox Code Playgroud) knitr将参数fig.cap定义为
fig.cap :( NULL; character)在LaTeX的数字环境中使用的数字标题(在\ caption {}中); 如果是NULL或NA,它将被忽略,否则图形环境将用于块中的图(在\ begin {figure}和\ end {figure}中输出)
但是,对于HTML输出,以下工作:
---
title: "Caption Test"
author: "Some Author"
date: "February 18, 2016"
output: html_document
---
```{r}
library(ggplot2)
```
```{r, fig.cap = c("This is caption 1", "This is caption 2")}
## Plot 1
qplot(carat, price, data = diamonds)
## Plot 2
qplot(carat, depth, data = diamonds)
```
Run Code Online (Sandbox Code Playgroud)
意思是,每个数字都会在代码块参数中定义正确的标题 fig.cap = c("Caption 1", "Caption 2")
但是,跟踪字幕是很有挑战性的 - 特别是如果长时间将它们放在块选项中.除了为每个图形创建两个单独的块,并且在块外部插入了标题,还有其他选项吗?
我有这样的数据:
structure(list(group = c("A", "A", "A", "A", "B", "B"), date = structure(c(1262304000,
1267401600, 1288569600, 1293840000, 1328054400, 1333238400), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), freq = c(5, 1, 20, 6, 2, 8)), .Names = c("group",
"date", "freq"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-6L))
> df
# A tibble: 6 x 3
group date freq
<chr> <dttm> <dbl>
1 A 2010-01-01 5
2 A 2010-03-01 1
3 A 2010-11-01 20
4 A 2011-01-01 6
5 B 2012-02-01 2 …Run Code Online (Sandbox Code Playgroud) 我想替换组内重复的元素
df <- data.frame(A=c("a", "a", "a", "b", "b", "c"), group = c(1, 1, 2, 2, 2, 3))
Run Code Online (Sandbox Code Playgroud)
我想保留组的第一个元素,同时用 NA 替换其他任何元素。就像是:
df <- df %>%
group_by(group) %>%
mutate(B = first(A))
Run Code Online (Sandbox Code Playgroud)
这不会产生我想要的。我想要的是B <- c(a, NA, a, NA, NA, c)