这是对"经典"Rmd文件的改编,我希望使用Emacs(Emacs Speak Statistics)和多态编码将其编织为pdf.我无法找到正确的命令来做到这一点.关于polymode的文档很少.我正在使用社交科学的Emacs入门套件.
---
title: "Untitled"
author: "SB"
date: "Wednesday, February 04, 2015"
output: pdf_document
---
You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Run Code Online (Sandbox Code Playgroud) 我有以下数据框df:
v1 v2 v3 v4
1 1 5 7 4
2 2 6 10 3
Run Code Online (Sandbox Code Playgroud)
我想获得以下数据帧df2乘法列v1*v3和v2*v4:
v1 v2 v3 v4 v1v3 v2v4
1 1 5 7 4 7 20
2 2 6 10 3 20 18
Run Code Online (Sandbox Code Playgroud)
我该怎么做dplyr呢?用mutate_each?
我需要一个可以推广到大量变量而不仅仅是4(v1到v4)的解决方案.这是生成示例的代码:
v1 <- c(1, 2)
v2 <- c(5,6)
v3 <- c(7, 10)
v4 <- c(4, 3)
df <- data.frame(v1, v2, v3, v4)
v1v3 <- c(v1 * v3)
v2v4 <- c(v2 * v4)
df2 …Run Code Online (Sandbox Code Playgroud) 我在Mac OS 10.12上使用pandoc v.1.18将这个markdown文件转换为pdf,使用一个简单的命令行:
# A list that does not work
- one
- two
- three
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
! Undefined control sequence.
l.53 \tightlist
pandoc: Error producing PDF
Run Code Online (Sandbox Code Playgroud)
怎么解决这个问题?
来自R我习惯于做这样的事情来获取 vector 的第一个元素a:
a <- c(1:3, 5)
a[1]
[1] 1
Run Code Online (Sandbox Code Playgroud)
H 我可以1进去Julia吗?的第一个元素a现在是 a range。
a = [1:3, 5]
a[1]
1-element Array{UnitRange{Int64},1}:
1:3
Run Code Online (Sandbox Code Playgroud) 当我尝试在RStudio中使用RMarkdown编织 pdf 时,此代码会产生错误。
如何在Fig.caption中写一个希腊字母,例如$\beta$?
---
title: "Untitled"
author: "SB"
date: "Thursday, January 29, 2015"
output:
pdf_document:
fig_caption: yes
---
```{r var, echo=FALSE, fig.cap="Cars variation rate between year $t$ and $t-1$ for $0 < \beta < 1$"}
plot(cars)
```
Run Code Online (Sandbox Code Playgroud) 我希望我的多折线图在 x 轴上仅显示年份(而不是年份和月份)。我尝试用“年”来格式化,"%Y"但df2显示日、月和年。
library(tidyverse)
theme_set(theme_minimal())
df <- tibble(
year = as.character(c(2015, 2016)),
v1 = c(3,10),
v2 = c(7,18))
df$year <- as.Date(df$year, "%Y")
format(df$year, "%Y")
#> [1] "2015" "2016"
df2 <- df %>%
gather(key = "variable", value = "value", -year)
ggplot(df2, aes(x = year, y = value)) +
geom_line(aes(color = variable, linetype = variable)) +
scale_color_manual(values = c("darkred", "steelblue"))
Run Code Online (Sandbox Code Playgroud) 想象一下,您发现某人编写了一个函数(例如countfrom)。如何找到一个函数所属的包?在这种情况下Iterators。
me我创建了包含三个 2D 数组的3D 数组。例如,我想删除第二个数组[:,:,2]并将结果复制到名为 的新数组you。
我尝试过deleteat!(me, :,:,2),但它给了我一个错误。
me = reshape(1:(5*5*3), 5, 5, 3)
Run Code Online (Sandbox Code Playgroud) 我想使用变量f_year而不是2004. 我该怎么做?
library(dplyr)\n#> \n#> Attaching package: 'dplyr'\n#> The following objects are masked from 'package:stats':\n#> \n#> filter, lag\n#> The following objects are masked from 'package:base':\n#> \n#> intersect, setdiff, setequal, union\n\nf_year <- "2004"\n\ndf <- tibble(`2004` = c(1,2),\n `2005` = c(1,4),\n `2006` = c(2,7))\ndf\n#> # A tibble: 2 \xc3\x97 3\n#> `2004` `2005` `2006`\n#> <dbl> <dbl> <dbl>\n#> 1 1 1 2\n#> 2 2 4 7\n\ndf2 <- df %>% mutate(`2004` = ifelse(`2004` == 1, 4, `2004`))\ndf2\n#> # A tibble: 2 …Run Code Online (Sandbox Code Playgroud) 我想使用函数将dataframe d转换为(result)的结果replace_by_sym。我究竟做错了什么?
library(tidyverse)
d <- data.frame(dir = c(-1,1,-1,1,1), a = rep(100,5), b = 105:109, c = 108:112)
replace_by_sym <- function(x){
x <- x * (-1) + 200
}
d %>%
mutate_if(dir=-1, vars(a:c),
funs(replace_by_sym(.))) -> result
Run Code Online (Sandbox Code Playgroud)
获得
dir a b c
1 -1 100 95 92
2 1 100 106 109
3 -1 100 93 90
4 1 100 108 111
5 1 100 109 112
Run Code Online (Sandbox Code Playgroud)