小编For*_*rge的帖子

dplyr重命名错误:包含未知变量

很简单,用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)

r dplyr

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

如何在 duckdb 上进行真空处理(减小文件大小)

我正在测试用于分析的 duckdb 数据库,我必须说速度非常快。问题是数据库文件越来越大,但我需要将其缩小以共享它。

在 sqlite 中,我记得使用 VACUUM 命令,但这里相同的命令什么也不做。尺寸是一样的。

如何减少duckdb数据库的文件大小?

duckdb

8
推荐指数
1
解决办法
2214
查看次数

如何在 Xaringan 幻灯片中嵌入视频 (avi/mpg4)

我正在尝试将一些本地视频嵌入到我的 xaringsn 演示文稿中。我已经成功嵌入了 GIF,但我需要更高的质量,并且 AVI 或 MPG4 是强制性的

问题是无论我使用 markdown 语法还是 html 语法都无法嵌入视频

![video](media/animation.avi)


<video width="320" height="240">
<source src="media/animation.mp4" type="video/mp4">
</video>
Run Code Online (Sandbox Code Playgroud)

任何提示将不胜感激

r-markdown xaringan

7
推荐指数
1
解决办法
1360
查看次数

无法在ubuntu服务器中安装rJava依赖项

我正在尝试安装一些软件包(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)

r rjava

7
推荐指数
0
解决办法
224
查看次数

如何用美丽的汤和熊猫刮桌子时保留链接

刮刮网来获取桌子,使用Beautiful soupPandas.其中一个专栏有一些网址.当我把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.

任何提示?

python beautifulsoup pandas

5
推荐指数
2
解决办法
3307
查看次数

gganimate 在 Windows 10 中渲染像素化

我必须使用 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)

我得到的是这样的:

在此输入图像描述

animation r ggplot2 gganimate

5
推荐指数
1
解决办法
951
查看次数

floating TOC for prettydoc in Rmarkdown ask for theme

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)

r r-markdown

5
推荐指数
1
解决办法
112
查看次数

Rmarkdown的TOC图像标志

我知道我可以使用带有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)

html r knitr r-markdown

4
推荐指数
1
解决办法
1144
查看次数

在Dockerfile中从Github添加R包以进行安装

如何使用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调用但无法计算命令.任何提示?

r docker

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

Byobu Shift + F2 在 Windows 上不起作用

在 Windows 10 系统上连接到 Ubuntu 16.04.3 LTS 中的 byobu,当我键入 Shift+F2 以获得垂直拆分时,没有任何反应。输入普通的 F2 工作并打开一个新窗口。Ctrl + F2 也可以垂直拆分。

我在 PuTTY/Kitty/ConEmu 配置(例如 XTerm R2、Linux)中尝试了所有终端键盘类型,但没有任何运气。有任何想法吗?有没有其他键盘快捷键可以做同样的事情?

terminal byobu ubuntu-16.04

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

使用dplyr group_split保留数据框名称

使用来自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)

r dplyr

2
推荐指数
1
解决办法
58
查看次数

从循环内的列表中获取数据框名称

我从环境中检索所有数据帧,然后执行一些操作:

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 名称本身。

任何提示将不胜感激

r

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

当 x 轴是日期时,将图像插入 ggplot + gganimate

我想使用 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)

r ggplot2 gganimate

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