在努力解决另一个问题时,我遇到了这个问题:
我可以删除所有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) 我想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
这个操作的正确语法是什么?
[TraitCollection] 类 CKBrowserSwitcherViewController 覆盖了 -traitCollection getter,不支持。如果您尝试覆盖特征,则必须使用适当的 API。
我在调试器中收到这条消息,因为我在我的应用程序中使用了 MFMessageComposeViewController、MFMailComposeViewController、CNContactPickerViewController,并用导航控制器呈现它们。我的导航控制器是在每个视图控制器文件上单独定制的。首先,我尝试在应用程序委托“didFinishLauching”方法中进行自定义,但这导致了一些显示这些内置控制器的问题。但只要我记得,当我尝试做后者时,我仍然收到上述消息。
我正在使用下面的代码生成带有一些注释的简单图表:
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)
在该图表上,我想将粗体字体应用于文本注释中短语的第一部分:
这应该是大胆的
但我希望文本的其余部分在字体和样式方面保持不变.
我正在尝试使用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) 以下代码重命名数据集中的第一列:
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) 目前我正在使用build in function dist来计算我在R中的距离矩阵.
dist(featureVector,method="manhattan")
Run Code Online (Sandbox Code Playgroud)
这是目前应用程序的瓶颈,因此我们的想法是平衡这项任务(概念上这应该是可能的)
搜索谷歌和这个论坛没有成功.
有人有想法吗?
我正在使用下面的代码生成以下图表.
# 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)

我目前正在尝试修改轴标题的显示.特别是,我希望轴标题是:
我正在尝试将一个相当混乱的列分成两列,其中包含句点和描述.我的数据类似于下面的摘录:
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)
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) 我正在使用以下代码:
# 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 ×9
dplyr ×3
ggplot2 ×2
scatter-plot ×2
annotations ×1
bibliography ×1
border ×1
charts ×1
dataframe ×1
distance ×1
ggally ×1
gridextra ×1
latex ×1
matrix ×1
na ×1
nse ×1
r-corrplot ×1
r-markdown ×1
regex ×1
rename ×1
rstudio ×1
spatial ×1
string ×1
swift ×1
text ×1
tidyr ×1
workspace ×1
xcode ×1