很简单,用dplyr重命名colnames会给我一个奇怪的错误.
library(dplyr)
df <- data.frame(var1=c("one","two","three"),var2=c(1,2,3))
df <-
df %>%
rename(var1=are.letters, var2=are.numbers)
Error: `are.letters`, `are.numbers` contains unknown variables
Run Code Online (Sandbox Code Playgroud)
第二次尝试
df <- rename(df, var1=are.letters, var2=are.numbers)
Error: `are.letters`, `are.numbers` contains unknown variables
Run Code Online (Sandbox Code Playgroud)
想知道是否引用....
df <-
df %>%
rename('var1'='are.letters', 'var2'='are.numbers')
Error: `are.letters`, `are.numbers` contains unknown variables
Run Code Online (Sandbox Code Playgroud) 我正在测试用于分析的 duckdb 数据库,我必须说速度非常快。问题是数据库文件越来越大,但我需要将其缩小以共享它。
在 sqlite 中,我记得使用 VACUUM 命令,但这里相同的命令什么也不做。尺寸是一样的。
如何减少duckdb数据库的文件大小?
我正在尝试将一些本地视频嵌入到我的 xaringsn 演示文稿中。我已经成功嵌入了 GIF,但我需要更高的质量,并且 AVI 或 MPG4 是强制性的
问题是无论我使用 markdown 语法还是 html 语法都无法嵌入视频

<video width="320" height="240">
<source src="media/animation.mp4" type="video/mp4">
</video>
Run Code Online (Sandbox Code Playgroud)
任何提示将不胜感激
我正在尝试安装一些软件包(mailR),以便能够通过邮件将错误和消息传达给我的用户,并通过rJdbc连接到HIVE服务器,但是随着步骤的完成,安装rJava依赖关系变得越来越复杂。
第一个错误是要求rJava软件包,因此我尝试安装rJava:
install.packages("rJava")
Installing package into ‘/home/joe/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/rJava_0.9-11.tar.gz'
Content type 'application/x-gzip' length 675188 bytes (659 KB)
==================================================
downloaded 659 KB
* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... gcc -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for …Run Code Online (Sandbox Code Playgroud) 刮刮网来获取桌子,使用Beautiful soup和Pandas.其中一个专栏有一些网址.当我把html传递给熊猫时,href就丢了.
是否有任何方法可以保留该列的URL链接?
示例数据(针对更好的案例进行编辑):
<html>
<body>
<table>
<tr>
<td>customer</td>
<td>country</td>
<td>area</td>
<td>website link</td>
</tr>
<tr>
<td>IBM</td>
<td>USA</td>
<td>EMEA</td>
<td><a href="http://www.ibm.com">IBM site</a></td>
</tr>
<tr>
<td>CISCO</td>
<td>USA</td>
<td>EMEA</td>
<td><a href="http://www.cisco.com">cisco site</a></td>
</tr>
<tr>
<td>unknown company</td>
<td>USA</td>
<td>EMEA</td>
<td></td>
</tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的python代码:
file = open(url,"r")
soup = BeautifulSoup(file, 'lxml')
parsed_table = soup.find_all('table')[1]
df = pd.read_html(str(parsed_table),encoding='utf-8')[0]
df
Run Code Online (Sandbox Code Playgroud)
输出(导出为CSV):
customer;country;area;website
IBM;USA;EMEA;IBM site
CISCO;USA;EMEA;cisco site
unknown company;USA;EMEA;
Run Code Online (Sandbox Code Playgroud)
df输出正常但链接丢失.我需要保留链接.至少URL.
任何提示?
我必须使用 gganimate 渲染一些动画,但图像不好看。它们缺乏清晰度,边界像素化。有什么方法可以在 Windows 10 中获得更好的结果吗?
我的代码是:
library(gapminder)
library(ggplot2)
library(gganimate)
Cairo(600, 600, file="plot.png", type="png", bg="white")
ggplot(gapminder,aes(gdpPercap, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~continent) +
# Here comes the gganimate specific bits
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) +
ease_aes('linear')
Run Code Online (Sandbox Code Playgroud)
我得到的是这样的:
I love floating TOCs in my Rmarkdown and prettydoc package but trying to use both seems impossible.
I just want to add a floating TOC to my HTML Pretty doc. This is my working yaml header
title: "testing TOCs"
author: "Joe"
output:
prettydoc::html_pretty:
theme: leonids
highlight: github
toc: true
Run Code Online (Sandbox Code Playgroud)
Adding Floating TOC option issues an error message asking for Theme.
title: "Test floating TOC"
author: "joe"
output:
prettydoc::html_pretty:
theme: leonids
highlight: github
toc: true
toc_float: true
Error in rmarkdown::html_document(fig_retina = …Run Code Online (Sandbox Code Playgroud) 我知道我可以使用带有in_header/before_body选项的knitr在HTML报告的顶部插入徽标或图像
output:
html_document:
includes:
before_body: header.Rhtml
Run Code Online (Sandbox Code Playgroud)
我的猜测是:如何在浮动TOC上渲染徽标?
output:
html_document:
toc: true
toc_float: true
collapsed: false
??????
Run Code Online (Sandbox Code Playgroud) 如何使用github和我的Dockerfile为R包添加安装指令.
R环境中的常用命令是:
devtools::install_github("smach/rmiscutils")
Run Code Online (Sandbox Code Playgroud)
但到目前为止没有成功.试图将github repo添加到安装说明中:
RUN install2.r --error \
-r 'http://cran.rstudio.com' \
-r 'http://github.com/smach/rmiscutils'
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
error in download. Status was '404 Not found'
Run Code Online (Sandbox Code Playgroud)
也许使用vanilla R调用但无法计算命令.任何提示?
在 Windows 10 系统上连接到 Ubuntu 16.04.3 LTS 中的 byobu,当我键入 Shift+F2 以获得垂直拆分时,没有任何反应。输入普通的 F2 工作并打开一个新窗口。Ctrl + F2 也可以垂直拆分。
我在 PuTTY/Kitty/ConEmu 配置(例如 XTerm R2、Linux)中尝试了所有终端键盘类型,但没有任何运气。有任何想法吗?有没有其他键盘快捷键可以做同样的事情?
使用来自dplyr的group_split,但我需要列表中的每个数据框都保留名称。
dplyr文档中的示例(注意,数据帧已编号。最佳输出是每个数据帧均具有分组变量的名称(Setosa,versicolor ...):
ir <- iris %>%
group_by(Species)
group_split(ir)
#> [[1]]
#> # A tibble: 50 x 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <fct>
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 5 5 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa
#> 7 4.6 3.4 1.4 0.3 setosa
#> …Run Code Online (Sandbox Code Playgroud) 我从环境中检索所有数据帧,然后执行一些操作:
dfs <- Filter(function(x) is(x, "data.frame"), mget(ls()))
names(dfs)
"customers"
"sales"
"campaigns"
Run Code Online (Sandbox Code Playgroud)
我需要提取的第一件事是循环内的对象名称:
for (df in dfs) {
df_name <- deparse(substitute(df))
# do some stuff
# do some more stuff
print(df_name)
}
Run Code Online (Sandbox Code Playgroud)
但我得到的是要操作的数据框名称:
"df"
"df"
"df"
Run Code Online (Sandbox Code Playgroud)
我也在循环内测试了一个函数:
find_name <- function(df) {
df_name_is <- substitute(df)
return(df_name_is)
}
Run Code Online (Sandbox Code Playgroud)
但输出是:
df
df
df
Run Code Online (Sandbox Code Playgroud)
循环namesdf 可以得到colnames每个 df 的 ,而不是 df 名称本身。
任何提示将不胜感激
我想使用 gganimate 对一些数据进行动画处理。以他们的 github 页面为例,我对其进行了一些更改以反映我的情况。X 轴是日期,我希望所有框架的徽标都位于相同位置。
可重现的代码:
library(magick)
library(gapminder)
library(ggplot2)
library(rsvg)
library(gganimate)
tiger <- image_read_svg('http://jeroen.github.io/images/tiger.svg', width = 400)
(p <- ggplot(gapminder, aes(year, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
annotation_raster(tiger, ymin = 75, ymax = 100, xmin = 1965, xmax = 2005) )
# here the animate part (not needed just for ilustrative purposes)
p + labs(title = 'Year: {frame_time}', x …Run Code Online (Sandbox Code Playgroud)