我在foreach包中发现了一个功能/错误,我不明白.也许有人可以解释我这种行为:
我用foreach
包创建了一个for循环(我将它们与mutlicore计算一起使用,但这里只是在一个sequentiell示例中,错误出现在两个变体中).这个循环运行r
时间.在每次运行中,c
都会返回包含条目的列表.所以我希望列表包含r
条目,每个条目都包含c
列表.
我的代码如下:
library(foreach)
clusters <- 10
runs <- 100
temp <- foreach(r = 1:runs,
.combine = 'list',
.multicombine = TRUE) %do% {
signal_all <- lapply(1:clusters, function(x){
return(1)
})
return(signal_all)
} ## end do
Run Code Online (Sandbox Code Playgroud)
使用此代码,所有工作都按预期工作,请参见下图:
但是当增加时runs <- 101
,输出temp
是这样的:
预期的列表结构被销毁.但是当评论出这一行时,.combine = 'list'
所有工作都按预期进行.
library(foreach)
clusters <- 10
runs <- 100
temp <- foreach(r = 1:runs,
.multicombine = TRUE) %do% {
signal_all <- lapply(1:clusters, function(x){
return(1)
}) …
Run Code Online (Sandbox Code Playgroud) 我有以下问题:我获得的数据中的日期列包含由于夏令时而不存在的日期.(例如2015-03-29 02:00在中欧时间不存在,因为时钟从01:59直接设置为03:00因为DST在这一天生效)
是否有一种简单可靠的方法来确定日期在夏令时方面是否有效?
由于datetime类的属性,这并非易事.
# generating the invalid time as POSIXlt object
test <- strptime("2015-03-29 02:00", format="%Y-%m-%d %H:%M", tz="CET")
# the object seems to represent something at least partially reasonable, notice the missing timezone specification though
test
# [1] "2015-03-29 02:00:00"
# strangely enough this object is regarded as NA by is.na
is.na(test)
# [1] TRUE
# which is no surprise if you consider:
is.na.POSIXlt
# function (x)
# is.na(as.POSIXct(x))
as.POSIXct(test)
# [1] NA
# inspecting the interior of my …
Run Code Online (Sandbox Code Playgroud) 请帮我
1)为什么map_if在列表中不起作用
2)是否有使其工作的方法
3)如果不可行,还有哪些选择
提前致谢。
library(dplyr)
library(purrr)
cyl <- split(mtcars, mtcars$cyl)
# This works
map_if(mtcars, is.numeric, mean)
# This does not work
map_if(cyl, is.numeric, mean)
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个包含方程式的文档,我希望方程式能够遵循换行符.当我编织HTML时这种方法很好,但是当我编写pdf时却没有.
$$
x_1 - ? +\\
x_2 - ? +\\
x_3 - ? +\\
$$
Run Code Online (Sandbox Code Playgroud)
我也试过\newline
,甚至\hfill \break
.我还尝试了在RStudio的RMarkdown备忘单上列出的不同乳胶发动机.
我希望你能为我在为R安装RCurl和卷曲包时遇到的这个问题提供帮助.
Rd warning: /tmp/RtmpOBkvFC/R.INSTALLd07e6c06faf4/RCurl/man/url.exists.Rd:5: missing file link ‘file.exists’
** building package indices
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/majaidi/R/x86_64-redhat-linux-gnu-library/3.1/RCurl/libs/RCurl.so':
/lib64/libgssapi_krb5.so.2: symbol krb5int_buf_len, version krb5support_0_MIT not defined in file libkrb5support.so.0 with link time reference
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/majaidi/R/x86_64-redhat-linux-gnu-library/3.1/RCurl’
The downloaded source packages are in
‘/tmp/RtmpX6poG4/downloaded_packages’
Warning message:
In install.packages(pkgs = pkgs, lib = lib, repos = repos, ...) : …
Run Code Online (Sandbox Code Playgroud) 例如,我有一个包含整数列和因子列的data.frame.
data <- data.frame(
a = 1:5,
b = factor(c("a", "b", "c", "d", "e")),
c = factor(c("f", "g", "h", "i", "j")))`
Run Code Online (Sandbox Code Playgroud)
我想将b和c因子列转换为字符,并将列a保持为整数.
我尝试了以下代码:
sapply(data, function(x) {if_else(is.factor(x), as.character(x), x)})
它没有得到结果,而是抛出一个错误:
错误:
true
必须是长度1(长度condition
),而不是5
我知道这可以通过dplyr中的mutate_if函数来完成.但我仍然想知道为什么我的代码不能用于这种情况.
非常感谢您的任何建议!
希望这不是重复的帖子。我查看了一些已经存在的相关问题,它要么与乳胶而不是 r-markdown 有关,要么与“beamer”类型输出有关。
我的程序使用 knitr 包。如果我尝试将 kable 表格式化为 Latex 格式,则会收到错误消息“!LaTeX 错误:包 xcolor 的选项冲突”。r-markdown 有解决方法吗?具体是什么原因导致冲突呢?
有没有办法将单个.md文件编织到R中工作目录中的.html或.docx,同时将.html的副本发布到另一个文件夹,可能在另一个驱动器上?
或者,可以使用RStudio中的"发布"按钮将.md文件发送到RPubs以外的位置吗?
我想知道是否有人使用 OPC-UA 通信标准开发R包。\n我在 CRAN 和 GitHub 上都没有找到 R 包。
\n我的想法是对 OPC-UA 服务器发送的数据进行一些实时分析。
\n有一些 python 包,但我不知道 R 是否适合该网络协议的语言。
\n在我看来,R非常适合可视化数据并分析它们。
\n