小编Kon*_*rad的帖子

在R工作时分离所有包裹

在努力解决另一个问题时,我遇到了这个问题:

我可以删除所有R对象:

rm(list = ls(all = TRUE))
Run Code Online (Sandbox Code Playgroud)

在工作会话期间是否有可以分离已安装软件包的等效命令?

> sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base 
Run Code Online (Sandbox Code Playgroud)

需要(GGPLOT2)

Loading required package: ggplot2
Loading required package: reshape
Loading required package: plyr

Attaching package: 'reshape'

The following object(s) are masked from 'package:plyr':

    round_any

Loading required package: grid
Loading required package: proto
Run Code Online (Sandbox Code Playgroud)

sessionInfo()

R version 2.12.2 (2011-02-25) …
Run Code Online (Sandbox Code Playgroud)

workspace r

87
推荐指数
5
解决办法
6万
查看次数

mutate_if的正确语法

我想NA通过mutate_ifin 用零替换值dplyr.语法如下:

set.seed(1)
mtcars[sample(1:dim(mtcars)[1], 5),
       sample(1:dim(mtcars)[2], 5)] <-  NA

require(dplyr)

mtcars %>% 
    mutate_if(is.na,0)

mtcars %>% 
    mutate_if(is.na, funs(. = 0))
Run Code Online (Sandbox Code Playgroud)

返回错误:

错误vapply(tbl, p, logical(1), ...):值必须为长度1,但FUN(X[[1]])结果为长度32

这个操作的正确语法是什么?

r na dplyr

48
推荐指数
3
解决办法
4万
查看次数

类 CKBrowserSwitcherViewController 覆盖了 -traitCollection getter...这个消息是什么意思?

[TraitCollection] 类 CKBrowserSwitcherViewController 覆盖了 -traitCollection getter,不支持。如果您尝试覆盖特征,则必须使用适当的 API。

我在调试器中收到这条消息,因为我在我的应用程序中使用了 MFMessageComposeViewController、MFMailComposeViewController、CNContactPickerViewController,并用导航控制器呈现它们。我的导航控制器是在每个视图控制器文件上单独定制的。首先,我尝试在应用程序委托“didFinishLauching”方法中进行自定义,但这导致了一些显示这些内置控制器的问题。但只要我记得,当我尝试做后者时,我仍然收到上述消息。

xcode swift

40
推荐指数
1
解决办法
2965
查看次数

在注释中使用不同的字体样式(ggplot2)

我正在使用下面的代码生成带有一些注释的简单图表:

require(ggplot2); data(mtcars)
ggplot(mtcars, aes(x = wt, y = mpg)) + 
  geom_point() +
  annotate("text", x = 4, y = 25, label = "This should be bold\nand this not",
           colour = "red") +
  geom_vline(xintercept = 3.2, colour = "red")
Run Code Online (Sandbox Code Playgroud)

简单的情节

在该图表上,我想将粗体字体应用于文本注释中短语的第一部分:

这应该是大胆的

但我希望文本的其余部分在字体和样式方面保持不变.

charts text annotations r ggplot2

22
推荐指数
3
解决办法
3万
查看次数

使用knitcitations在RMarkdown文档中包含参考书目

我正在尝试使用knitcitations并将参考书目添加到我正在R Studio中起草的R Markdown文档中.我的文档的标题如下所示:

---
title: "Some Title"
author: "Me"
date: "September 2015"
bibliography: bibliography.bib
output:
  pdf_document: 
    highlight: tango
    number_sections: yes
    toc: yes
---
Run Code Online (Sandbox Code Playgroud)

我想使用以下代码在最后添加参考书目:

```{r generateBibliography, echo=FALSE, eval=TRUE, message=FALSE, warning=FALSE}
require("knitcitations")
cleanbib()
options("citation_format" = "pandoc")
read.bibtex(file = "bibliography.bib")
```
Run Code Online (Sandbox Code Playgroud)

参考文件bibliography.bib具有以下内容:

@article{debarsy_testing_2010,
    title = {Testing for spatial autocorrelation in a fixed effects panel data model},
    volume = {40},
    issn = {0166-0462},
    url = {http://www.sciencedirect.com/science/article/pii/S0166046210000451},
    doi = {10.1016/j.regsciurbeco.2010.06.001},
    abstract = {The aim of this paper is to assess …
Run Code Online (Sandbox Code Playgroud)

latex r bibliography rstudio r-markdown

20
推荐指数
3
解决办法
2万
查看次数

如何通过列索引dplyr重命名列?

以下代码重命名数据集中的第一列:

require(dplyr)    
mtcars %>%
        setNames(c("RenamedColumn", names(.)[2:length(names(.))]))
Run Code Online (Sandbox Code Playgroud)

期望的结果:

                    RenamedColumn cyl  disp  hp drat    wt  qsec vs am gear carb
Mazda RX4                    21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag                21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
Datsun 710                   22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
Run Code Online (Sandbox Code Playgroud)

是否可以使用和列索引得到相同的结果rename

这个:

mtcars %>%
    rename(1 = "ChangedNameAgain")
Run Code Online (Sandbox Code Playgroud)

将失败:

Error in source("~/.active-rstudio-document", echo = TRUE) : 
  ~/.active-rstudio-document:7:14: unexpected '=' …
Run Code Online (Sandbox Code Playgroud)

r rename dataframe dplyr nse

17
推荐指数
3
解决办法
1万
查看次数

R中的平行距离矩阵

目前我正在使用build in function dist来计算我在R中的距离矩阵.

dist(featureVector,method="manhattan")
Run Code Online (Sandbox Code Playgroud)

这是目前应用程序的瓶颈,因此我们的想法是平衡这项任务(概念上这应该是可能的)

搜索谷歌和这个论坛没有成功.

有人有想法吗?

parallel-processing r distance spatial matrix

16
推荐指数
2
解决办法
4988
查看次数

在ggpairs中操纵轴标题(GGally)

我正在使用下面的代码生成以下图表.

# Setup
data(airquality)

# Device start
png(filename = "example.png", units = "cm", width = 20, height = 14, res = 300)

# Define chart
pairs.chrt <- ggpairs(airquality,
                      lower = list(continuous = "smooth"),
                      diag = list(continuous = "blank"),
                      upper = list(continuous = "blank")) +
  theme(legend.position = "none",
        panel.grid.major = element_blank(),
        axis.ticks = element_blank(),
        axis.title.x = element_text(angle = 180, vjust = 1, color = "black"),
        panel.border = element_rect(fill = NA))

# Device off and print
print(pairs.chrt)
dev.off()
Run Code Online (Sandbox Code Playgroud)

ggpairs  - 第一个例子

我目前正在尝试修改轴标题的显示.特别是,我希望轴标题是:

  1. 放置在距离轴标签更远的位置 …

r scatter-plot ggally r-corrplot

15
推荐指数
2
解决办法
9963
查看次数

在第一个遇到的数字上使用单独的(tidyr)通过dplyr分离色谱柱

我正在尝试将一个相当混乱的列分成两列,其中包含句点描述.我的数据类似于下面的摘录:

set.seed(1)
dta <- data.frame(indicator=c("someindicator2001", "someindicator2011",
                              "some text 20022008", "another indicator 2003"),
                  values = runif(n = 4))
Run Code Online (Sandbox Code Playgroud)

期望的结果

期望的结果应该是这样的:

          indicator   period    values
1     someindicator     2001 0.2655087
2     someindicator     2011 0.3721239
3         some text 20022008 0.5728534
4 another indicator     2003 0.9082078
Run Code Online (Sandbox Code Playgroud)

特点

  1. 指标描述在一列中
  2. 数值(从第一个数字计数第一个数字是在第二列)

require(dplyr); require(tidyr); require(magrittr)
dta %<>%
  separate(col = indicator, into = c("indicator", "period"),
           sep = "^[^\\d]*(2+)", remove = TRUE)
Run Code Online (Sandbox Code Playgroud)

当然这不起作用:

> head(dta, 2)
  indicator period    values
1              001 0.2655087
2              011 …
Run Code Online (Sandbox Code Playgroud)

regex string r dplyr tidyr

14
推荐指数
1
解决办法
2260
查看次数

如何在gridExtra中通过arrange.grid创建的图表周围添加边框,其中包含一组ggplot2散点图

我正在使用以下代码:

# Libs
require(ggplot2); require(gridExtra); require(grid)

# Generate separate charts
chrts_list_scts <- list()

# Data
data("mtcars")

# A
chrts_list_scts$a <- ggplot(mtcars) +
  geom_point(size = 2, aes(x = mpg, y = disp,
                           colour = as.factor(cyl))) +
  geom_smooth(aes(x = mpg, y = disp),
              method = "auto") +
  xlab("MPG") +
  ylab("Disp") +
  theme_bw() +
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.position = "none")

# B
chrts_list_scts$b <- ggplot(mtcars) +
  geom_point(size = 2, aes(x = mpg, y = drat,
                           colour = as.factor(cyl))) +
  geom_smooth(aes(x …
Run Code Online (Sandbox Code Playgroud)

r border scatter-plot ggplot2 gridextra

13
推荐指数
1
解决办法
3913
查看次数