我正在使用Rmarkdown来创建文档.我想要包含降价表,但它们都缩放到页面的宽度.我想为表格指定相对宽度... 40%.我尝试了与以下相关的各种选项:
library(pander)
pandoc.table(head(cars))
library(xtable)
print(xtable(head(cars)), type="html")
library(knitr)
kable( head(cars), format="markdown")
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢
我想运行一个执行时间不到一秒的函数.我想每秒循环运行它.我不想像运行那样在运行函数之间等待一秒钟Sys.sleep.
while(TRUE){
# my function that takes less than a second to run
Sys.sleep(runif(1, min=0, max=.8))
# wait for the remaining time until the next execution...
# something here
}
Run Code Online (Sandbox Code Playgroud)
我可以记录一个starttime <- Sys.time()并在循环中每次迭代进行比较,就像这样......
starttime <- Sys.time()
while(TRUE){
if(abs(as.numeric(Sys.time() - starttime) %% 1) < .001){
# my function that takes less than a second to run
Sys.sleep(runif(1, min=0, max=.8))
print(paste("it ran", Sys.time()))
}
}
Run Code Online (Sandbox Code Playgroud)
但我的功能似乎永远不会被执行.
我知道python有一个包来做这种事情.R还有一个我不知道的吗?谢谢.
我正在尝试使用rvest从Wikipedia 抓取不规则表格。该表具有跨越多行的单元格。该文档的html_table明确规定,这是一个限制。我只是想知道是否有解决方法。
该表如下所示:

我的代码:
library(rvest)
url <- "https://en.wikipedia.org/wiki/Arizona_League"
parks <- url %>%
read_html() %>%
html_nodes(xpath='/html/body/div[3]/div[3]/div[4]/div/table[2]') %>%
html_table(fill=TRUE) %>% # fill=FALSE yields the same results
.[[1]]
Run Code Online (Sandbox Code Playgroud)
返回此:
例如,在存在多个错误的地方:“城市”下的第4行应为“ Mesa”,而不是“芝加哥小熊队”。我对空白单元格感到满意,因为我可以根据需要“填充”,但是错误的数据是一个问题。非常感谢您的帮助。
我有一个闪亮的应用程序,它通过selectizeInput输入并将数据输入固定大小的数据帧,当用户输入数据时,该数据帧显示和更新.当用户输入数据时,填写数据帧.每次用户输入新数据时,我都会使用googlesheets包将更改后的数据框上传到google工作表.此上传过程需要2或3秒,闪亮的应用程序将在更新UI并显示数据框之前等待它完成.保存到Google工作表的过程应该是一个后台任务,并且没有闪亮的应用程序等待它完成.有没有办法实现这个目标?
这是它的样子......
observeEvent(input$timer_start,
{
tmp <- row_col(val$cell, input$team_num)
val$df[tmp$row, tmp$col] <- input$name
tmp_df <<- val$df
edit_cells(gs, ws=1, tmp_df, header=TRUE)
})
Run Code Online (Sandbox Code Playgroud) 所以,我想在我的 ggplot 中添加一个标志页脚,但我想通过一个我可以使用+运算符的函数来做到这一点,所以我可以这样做:qplot(1:10, 1:10) + add_mylogo()
我可以用这个得到我想要的:
library(magick)
library(ggplot2)
mylogo <- image_scale(image_read("https://upload.wikimedia.org/wikipedia/commons/f/f7/Stack_Overflow_logo.png"), "180")
qplot(1:10, 1:10) + labs(caption="")
grid::grid.raster(mylogo, x = .97, y = .02, just = c('right', 'bottom'), width = unit(1.2, 'inches'))
Run Code Online (Sandbox Code Playgroud)
其中产生:
我的问题是我想+用来将它添加到情节中。
然后我尝试了这个:
library(cowplot)
library(magick)
library(ggplot2)
mylogo <- image_scale(image_read("https://upload.wikimedia.org/wikipedia/commons/f/f7/Stack_Overflow_logo.png"), "380")
qplot(1:3, 1:3)+ labs(caption="") +
draw_image(mylogo, x=3, y = .2, hjust=.7, vjust=0, scale = .5, clip=TRUE)
Run Code Online (Sandbox Code Playgroud)
其中产生:
所以现在我让它与+操作员一起工作,但我无法弄清楚如何使用任何类型的相对定位。我看到这篇关于使用相对定位的帖子annotate并尝试过,但它不起作用
qplot(1:3, 1:3)+ labs(caption="") +
draw_image(mylogo, x = -Inf, y …Run Code Online (Sandbox Code Playgroud) 我有这样的字符串:
a <- "this string has an even number of words"
b <- "this string doesn't have an even number of words"
Run Code Online (Sandbox Code Playgroud)
我想用新线替换所有其他空间.所以输出看起来像这样......
myfunc(a)
# "this string\nhas an\neven number\nof words"
myfunc(b)
# "this string\ndoesn't have\nan even\nnumber of\nwords"
Run Code Online (Sandbox Code Playgroud)
我已经做了做到了这一点strsplit,paste-ing在偶数字换行,然后paste(a, collapse=" ")他们重新走到一起成一个字符串.是否有正则表达式gsub可以实现这一点?