我有这样的数据集:
df = data.frame(group = c(rep('A',4), rep('B',3)),
subgroup = c('a', 'b', 'c', 'd', 'a', 'b', 'c'),
value = c(1,4,2,1,1,2,3))
group | subgroup | value
------------------------
A | a | 1
A | b | 4
A | c | 2
A | d | 1
B | a | 1
B | b | 2
B | c | 3
Run Code Online (Sandbox Code Playgroud)
我想要的是获得每个组中每个子组的值的百分比,即输出应该是:
group | subgroup | percent
------------------------
A | a | 0.125
A | b | 0.500
A | c …Run Code Online (Sandbox Code Playgroud) 我的rmarkdown脚本如下所示:
---
title: "Untitled"
author: "me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
pdf_document: default
bibliography: bibliography.bib
---
In his book Helsel explains how to approach censored environmental data [@helsel_statistics_2012].
Run Code Online (Sandbox Code Playgroud)
我的.bib文件如下:
@book{helsel_statistics_2012,
address = {Hoboken, N.J},
edition = {2nd ed},
series = {Wiley series in statistics in practice},
title = {Statistics for censored environmental data using {Minitab} and {R}},
isbn = {978-0-470-47988-9},
publisher = {Wiley},
author = {Helsel, Dennis R.},
year = {2012},
note = {00003 OCLC: ocn748290711},
keywords = …Run Code Online (Sandbox Code Playgroud) 假设我正在使用starwarsdplyr 包中的数据集,其中包含列表列(用于电影、车辆...)。为了简单起见,我们只使用名称和电影数据:
library(dplyr)
ex_data <- starwars %>%
select(name, films)
ex_data
# A tibble: 87 x 2
name films
<chr> <list>
1 Luke Skywalker <chr [5]>
2 C-3PO <chr [6]>
3 R2-D2 <chr [7]>
4 Darth Vader <chr [4]>
5 Leia Organa <chr [5]>
6 Owen Lars <chr [3]>
7 Beru Whitesun lars <chr [3]>
8 R5-D4 <chr [1]>
9 Biggs Darklighter <chr [1]>
10 Obi-Wan Kenobi <chr [6]>
# ... with 77 more rows
Run Code Online (Sandbox Code Playgroud)
我想将此数据复制到 PostgreSQL 数据库,但我希望在 SQL …
我在R中有一个data.frame/data.table,如下所示:
df <- data.frame(
ID=c(rep("A", 20)),
year=c(1968, 1971, 1972, 1973, 1974, 1976, 1978, 1980, 1982, 1984, 1985,
1986, 1987, 1988, 1990, 1991, 1992, 1993, 1994, 1995))
Run Code Online (Sandbox Code Playgroud)
我想将df分配,以便仅保留连续至少五年的条目.在这个例子中,这是两个时期的情况(1984:1988和1990:1995).我怎么能在R中这样做?谢谢你的支持.
我目前正在用德语写一份小报告。因此,我希望将图形标题从图1更改为Abbildung 1,依此类推。
---
title: "Untitled"
author: "me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
pdf_document: default
---
```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```
Run Code Online (Sandbox Code Playgroud)
问题:如何在R Markdown中更改默认的图形标题(不确定是否真的如此调用)?
我的Rmarkdown脚本最近变得越来越大。尤其是R-chunk中的代码,使得对整个脚本的预览越来越棘手。幸运的是,RStudio中有关闭响应的功能。将代码块最小化到一行!但是,当块变得越来越多时,需要花费时间手动关闭它们。
问题:是否有一个功能可以一次将其全部关闭?在开始处理脚本时说,然后在需要时重新打开单个块。
PS:不确定将其作为功能请求发布在github或此处。
我使用基因组数据来绘制三核苷酸的频率。我想用ggplot2生成png绘图,并且我在 Linux Centos 计算机上工作。如图所示,x.axis 标签未完全对齐,因为字母大小不同。我想使用等宽字体,所以我尝试使用“family”参数来修改主题,但这没有效果。我已经使用“extrafont”包看到并测试了许多答案,但没有结果,因为它似乎不适用于 png 输出。有没有一种简单的方法可以在 ggplot2 中使用等宽字体(例如 Courier),使用或不使用附加包?
这是迄今为止我基于最小数据集的代码示例。
testData <- data.frame(freq = rnorm(10),
context = c("ACA","ACC","ACG","ACT","CCA",
"CCC","CCG","CCT","GCA","GCC"))
a <- ggplot(testData, aes(x=context, y=freq)) +
geom_bar(stat="identity", width = 0.4, fill = "royalblue") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5,
size = 10, family = "mono"),
axis.title.x=element_blank())
ggsave("test.png",
plot=a,
width=2, height=2,
device = "png",
dpi = 300,
type = "cairo")
Run Code Online (Sandbox Code Playgroud) 我正在运行 PostgreSQL 服务器并将共享缓冲区限制为 4GB。
当我在数据库中插入大量记录时,检查点进程开始消耗 RAM。即使一天后,此过程也不会结束或减少 RAM 消耗。
知道为什么会发生这种情况吗?
我正在通过fdw_postgres访问不同数据库的数据。它运作良好:
CREATE FOREIGN TABLE fdw_table
(
name TEXT,
area double precision,
use TEXT,
geom GEOMETRY
)
SERVER foreign_db
OPTIONS (schema_name 'schema_A', table_name 'table_B')
Run Code Online (Sandbox Code Playgroud)
但是,当我查询data_typefdw_table 的时,我得到以下结果:
name text
area double precision
use text
geom USER-DEFINED
fdw_postgres不能处理PostGIS的GEOMETRY数据类型吗?在这种情况下,用户定义是什么意思?
给定一个数据框如下:
df <- data.frame(city = c("bj", "sh", "gz", "sz"),
price = c(12, 7, 5, 6),
pct = c(-2.3, 5, -4, 4), stringsAsFactors=FALSE)
Run Code Online (Sandbox Code Playgroud)
出去:
city price pct
0 bj 12 -2.3
1 sh 7 5.0
2 gz 5 -4.0
3 sz 6 4.0
Run Code Online (Sandbox Code Playgroud)
我想用 ggplot: barchartfor city, pointfor绘制一个图pct,但我想为负值和正值使用不同的颜色。
我怎样才能在ggplot2中做到这一点?
代码:
ggplot(df, aes(fill = city, y = price, x = city)) +
geom_bar(position = "dodge", stat = "identity", alpha = 0.5, fill = "#FF6666") +
geom_point(data = …Run Code Online (Sandbox Code Playgroud) r ×8
postgresql ×3
ggplot2 ×2
markdown ×2
pandoc ×2
bibliography ×1
bookdown ×1
data.table ×1
dataframe ×1
dplyr ×1
knitr ×1
latex ×1
plyr ×1
postgis ×1
r-markdown ×1
rstudio ×1