我正在尝试在 R 中使用多个 png 文件创建一个简短的动画。我尝试了 package magick,但只有当我将它们保存为 .gif 时它才有效。当我尝试另存为 .mp4 时,它将生成一个 .mp4 文件,但一旦打开它,只会显示第一张图像。
我的代码是
library(magick)
productPath <- ('/Users/abc/Desktop/products/')
list <- list.files(productPath, '*.png')
imagesPath <- paste0(productPath, list)
images <- image_read(imagesPath)
animation <- image_animate(images, fps = 20, loop = 1)
image_write(animation, paste0(productPath, 'test.mp4'))
Run Code Online (Sandbox Code Playgroud)
我发现还有一个名为 的包animation,但我真的不知道如何使用该包导入 png 文件。有什么解决办法吗?任何一个包都应该没问题。谢谢你!
我在Shiny服务器中遇到了for循环的问题,到目前为止,没有人能找到解决方法。我已经为此工作了好几天,但仍然没有任何进展。长话短说,请只看下面的代码。我试图从Google财经中获取数据并计算出平滑的方差。
stock2 <-
reactive(
getSymbols(
toupper(input$ticker2),
from = as.Date(input$date2[1]) - 150,
to = input$date2[2],
src = "google",
auto.assign = F
)
)
stock3 <- reactive(as.data.table(stock2()))
stock <- reactive(as.data.frame(stock3()))
stock.return <- reactive(diff(log(stock()[, 5])))
stock.mu <- reactive(mean(stock.return()))
stock.var <- reactive((stock.return() - stock.mu()) ^ 2)
stock.var.smoothed <- reactive(rep(0, length(stock.return())))
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,我已经测试过了。
所以问题是下面的代码,我想基于一些计算来分配向量,但是我不知道正确的方法。
stock.var.smoothed <- reactive({
for (i in 2:length(stock.var())) {
stock.var.smoothed[1] <<- stock.var()[1]
stock.var.smoothed[i] <<-
(1 - input$alpha) * stock.var.smoothed()[i - 1] + input$alpha * stock.var()[i]
}
})
Run Code Online (Sandbox Code Playgroud)
for循环根本不起作用。错误代码是
错误:“关闭”类型的对象不可子集化
但是我已经在函数中使用了()作为变量。所以我不知道该如何解决。
顺便说一句,我也尝试了以下代码
for (i …Run Code Online (Sandbox Code Playgroud) I\xe2\x80\x99m 尝试使用quantmodR 中的包从雅虎获取财务数据。它在我的个人笔记本电脑(Mac 和 Win)上完美运行。但我无法让它在我的工作计算机(Win7)上运行。
我的代码是:
\ngetSymbols("JPM", src = "yahoo")\nRun Code Online (Sandbox Code Playgroud)\n请注意,它仅不适用于我公司的笔记本电脑。
\n这是错误代码:
\nError in curl::curl_download(cu, tmp, handle = h) : \nSSL certificate problem: unable to get local issuer certificate\nRun Code Online (Sandbox Code Playgroud)\n我尝试通过以下方式解决问题:
\n安装httr包
删除curl并quantmod重新安装
更新到最新版本的 R、RStudio curl、、、httr和RCurlquantmod
安装openssl包
放ssl_verifypeer = 0L
之前添加以下内容getSymbols
options(download.file.method = "wget", download.file.extra …
我正在使用enum构造函数构建一个 Blackjack 卡类。
当我尝试调用我的构造函数时,我得到了java.lang.NullPointerException.
我已经阅读了一些线程,说它是关于引用的,null但我仍然不明白为什么我会收到这个错误。
请参阅下面的我的代码(它编译,但给出错误)
public class Card {
/**
* each card should have a suit and a rank
*/
// Create enumeration for suits, use our abbreviation as the String value
enum SUIT {
SPADE ("S"),
HEART ("H") ,
CLUB ("C"),
DIAMOND ("D");
// need constructor
private String abbreviation;
private SUIT(String abbreviation) {
this.abbreviation = abbreviation;
}
}
// Create enumeration for ranks with String abbreviation and int value
enum RANK …Run Code Online (Sandbox Code Playgroud)