我需要让列表的元素满足谓词和这些元素的索引.我可以这样做:
import Data.List (findIndices)
list :: [Int]
list = [3,2,4,1,9]
indices = findIndices (>2) list
elems = [list!!i | i <- indices]
-- same as: elems = filter (>2) list
Run Code Online (Sandbox Code Playgroud)
是不是有一个包提供了一个功能,以"一次性"给出元素及其索引?我很惊讶我在某处找不到这个功能.否则,如何做这样的功能,改进我上面的代码?我不相信这段代码是最优的,因为它以某种方式访问列表的元素两次.我快速浏览了一下源代码,findIndices但我还不明白.
现在,我正在制作一些包裹。作为测试数据,我想将 xlsx 文件包含在包中。不过我不知道方法,所以请告诉我。
想象:
myfunct <- function(x, ...){
dots <- list(...)
...
}
Run Code Online (Sandbox Code Playgroud)
如何在函数过程中区分点是从myfunct('something')(无点)还是myfunct('something', NULL)(点包括显式NULL)派生的?在我的实验两种情况下会导致is.null(dots)等同于TRUE。
在我的 flexdashboard 中,我使用“plotly”库来绘制图表。当数据刷新时,条形尺寸会减小。当时,当我单击“自动缩放”选项时,它工作正常。我的问题是我们可以通过plotly.r代码中的任何选项自动启用自动缩放吗?
我有一个这样的功能:
jac :: Int -> Int -> [Int] -> [Int] -> IOArray (Int,Int) Double -> IO Double
jac m k mu nu arr
| nu!!0 == 0 = return 1
| length nu > m && nu!!m > 0 = return 0
| m == 1 = return $ x!!0^(nu!!0) * theproduct (nu!!0)
| k == 0 && CONDITION = XXX
| otherwise = YYY
Run Code Online (Sandbox Code Playgroud)
在CONDITION必须检查该元素(1,1)的数组arr不同于0。但得到这个元素,一个必须做
element <- readArray arr (1,1)
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么办。除外unsafePerformIO。在这里使用安全吗?我的意思是: …
我正在学习如何使用图像作为单选按钮。
我找到了这个页面并一直在玩它: 你能有一个图像作为闪亮的单选按钮选择吗?
这里的答案非常有用,但应用程序不会加载单选按钮的 Rlogo(当使用函数使用答案的第二部分时)。我已将图像保存到 www 文件中。我尝试过用不同的方式编写该行,'<img src="Rlogo.png">' = 'logo'例如删除引号、将其替换为img(src='Rlogo.png') = 'logo'、将其替换为网络链接,但均不成功。请有人指出我哪里出错了,或者原始代码是否适合您!
徽标在这里:http://i1.wp.com/www.r-bloggers.com/wp-content/uploads/2016/02/Rlogo.png ?resize=300%2C263
代码是从页面复制过来的:
library(shiny)
radioButtons_withHTML <- function (inputId, label, choices, selected = NULL, inline = FALSE,
width = NULL)
{
choices <- shiny:::choicesWithNames(choices)
selected <- if (is.null(selected))
choices[[1]]
else {
shiny:::validateSelected(selected, choices, inputId)
}
if (length(selected) > 1)
stop("The 'selected' argument must be of length 1")
options <- generateOptions_withHTML(inputId, choices, selected, inline,
type = "radio")
divClass <- "form-group shiny-input-radiogroup shiny-input-container"
if (inline)
divClass …Run Code Online (Sandbox Code Playgroud) 我一直以为cld输出中的那一栏microbenchmark是速度的统计排名。然而事实并非如此:
> microbenchmark(
+ intmap = fintmap(), # slower
+ List = flist(),
+ times = 5
+ )
Unit: microseconds
expr min lq mean median uq max neval cld
intmap 793.984 910.539 1145.8608 911.840 1290.529 1822.412 5 a
List 1.092 1.318 201.3712 1.639 3.660 999.147 5 b
Run Code Online (Sandbox Code Playgroud)
那么它是什么?该文件只说这是一个统计排名,但是什么?
或者也许这是速度的多重比较测试,但标准差的不等性会导致这样的问题?第二个基准显然存在异常值。
看来我的问题没有说清楚。a我知道字母和的含义b,这是报告 Tukey 测试的经典方法。但这里的结果并不一致:intmap速度较慢但排名第一。
Sometimes, when I do git pull origin master from a local branch, I get merge conflicts like:
<<<<<<HEAD
======
>>>>>>xxxxxx
Run Code Online (Sandbox Code Playgroud)
How to avoid that ? Maybe it is due to some white spaces, so I tried to put a .gitattributes file containing * -whitespace but that didn't solve the problem.
我正在使用openxlsxr 来创建具有某些格式参数的 Excel 文件。以下是可重用的代码:
library(openxlsx)
wb <- createWorkbook()
addWorksheet(wb, "TestSheet")
df <- mtcars
df$Car <- row.names(mtcars)
row.names(df) <- NULL
df <- df[,c(length(df), 1:length(df)-1)]
forTopTit <- createStyle(fontColour = "#ffffff", fgFill = "#F4D03F",halign = "center",wrapText = TRUE,valign = "center")
forColHdr <- createStyle(fontColour = "#ffffff", fgFill = "#4F81BD",halign = "center",wrapText = TRUE,valign = "center")
forDatStl <- createStyle(fontColour = "#ffffff", halign="center")
writeData(wb,"TestSheet", "THIS IS A TEST MESSAGE", startCol = 1,startRow = 1,colNames = FALSE, rowNames = TRUE,
headerStyle = forTopTit,borders = "surrounding",borderStyle …Run Code Online (Sandbox Code Playgroud)