当我尝试在Mac上安装scapy时,我收到此错误:
Collecting scapy
Downloading scapy-2.3.1.zip (1.1MB)
100% |????????????????????????????????| 1.1MB 436kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/private/tmp/pip-build-f7vu4fsp/scapy/setup.py", line 35
os.chmod(fname,0755)
^
SyntaxError: invalid token
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-f7vu4fsp/scapy
Run Code Online (Sandbox Code Playgroud)
我试过用pip install scapy和pip3 install scapy.
有人对使用dplyr包的这种结果有解释吗?
我有一个 data.frame df
library(dplyr)
df = data_frame(
'id' = c(1,2,2,2,2,3,3,3,3),
'start' = c(881, 1611, 1611, 1642, 1764, 0, 0, 28, 59),
'end' = c(1089, 1819, 1819, 1850, 1972, 208, 208,236, 267))
Run Code Online (Sandbox Code Playgroud)
那看起来像
# Source: local data frame [9 x 3]
#
# id start end
# (dbl) (dbl) (dbl)
# 1 1 881 1089
# 2 2 1611 1819
# 3 2 1611 1819
# 4 2 1642 1850
# 5 2 1764 1972
# 6 3 …Run Code Online (Sandbox Code Playgroud) 我知道之前已经问过这个问题,但我不太明白.
我有一个如下所示的数据集:
Precinct Crime 2000 2001 2002 2003
1 Murder 3 1 2 2
1 Rape 12 5 10 11
1 Burglary 252 188 297 403
2 Murder 4 2 1 0
Run Code Online (Sandbox Code Playgroud)
以及每年列出的每项犯罪的价值.
我正在尝试将其重新排列为更简单的集合,如下所示:
Precinct Crime Year Value
1 Murder 2000 3
1 Rape 2000 12
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?我知道我应该使用tidyr gather,但推断多个键的解决方案并不适合我.
很多时候,我发现自己在dplyr中手动组合了select()和mutate()函数.这通常是因为我正在整理数据框,想要根据旧列创建新列,并且只想保留新列.
例如,如果我有关于高度和宽度的数据但只想使用它们来计算并保留该区域,那么我将使用:
library(dplyr)
df <- data.frame(height = 1:3, width = 10:12)
df %>%
mutate(area = height * width) %>%
select(area)
Run Code Online (Sandbox Code Playgroud)
当在mutate步骤中创建了许多变量时,可能很难确保它们都在选择步骤中.有没有更优雅的方法来保留mutate步骤中定义的变量?
我一直在使用的一个解决方法如下:
df %>%
mutate(id = row_number()) %>%
group_by(id) %>%
summarise(area = height * width) %>%
ungroup() %>%
select(-id)
Run Code Online (Sandbox Code Playgroud)
这有效,但非常冗长,使用summarize()意味着性能受到影响:
library(microbenchmark)
microbenchmark(
df %>%
mutate(area = height * width) %>%
select(area),
df %>%
mutate(id = row_number()) %>%
group_by(id) %>%
summarise(area = height * width) %>%
ungroup() %>%
select(-id)
)
Run Code Online (Sandbox Code Playgroud)
输出:
min lq mean median uq max neval cld
868.822 954.053 …Run Code Online (Sandbox Code Playgroud) 我不太确定 gitlab CI 工作流程应该如何实现这一点:
我想用 gitlab CI 做什么:
grunt bump执行概括
所以 grunt bump应该只在 master 上并且在成功的测试和合并之后执行。仅对于生成的提交(Release vx.xx),应该完成构建和部署工作...
也许有一个比这个想法更聪明的工作流程。基本上我想在合并和成功测试后增加版本值并标记提交......
我对 YAML 文件的尝试
stages:
- test
- build
- deploy
lint:
image: testing:latest
stage: test
tags:
- testing
script:
- /node_modules/.bin/eslint --ext .js --ext .jsx .
bump:
stage: build
tags:
- deploy
script:
- grunt bump
only:
- master
- /^Merge .*$/ …Run Code Online (Sandbox Code Playgroud) 我正在使用knitr::rmarkdown(但knitr::knitr功能相同)作为我的VignetteEngine。然后,我使用构建包小插图devtools::build_vignettes()。
这可行,但仅在中创建HTML和R输出文件inst/doc。我想要的是Markdown输出文件,因为只有该文件可以直接在Github项目页面中显示(对于HTML文件,Github显示源,对于Rmd文件,它显示渲染的输出,但是-显然-不执行R块)。
我已经尝试找出如何为custom VignetteEngines 指定输出,并且我认为应该有可能(毕竟,其他软件包至少使用它来构建PDF vignettes),但是我找不到通过这样做的方法devtools::build_vignettes。是否没有办法手动构建小插图(即通过knitr::knit忽略VignetteBuilder指令的类似机制)?
我也无法在文档/源中找到相关信息。
我在R中有一个金融时间序列(目前是一个xts对象,但我现在也在研究tibble).
如何找到与条件匹配的2个相邻行的概率?
例如,我想知道连续2天的概率高于平均值/中值.我知道lag前几天我可以进入下一行,这样可以让我得到这个统计数据,但这看起来非常麻烦且不灵活.
有没有更好的方法来完成这项工作?
xts样本数据:
foo <- xts(x = c(1,1,5,1,5,5,1), seq(as.Date("2016-01-01"), length = 7, by = "days"))
Run Code Online (Sandbox Code Playgroud)
连续2天高于median值的概率是多少?
使用 Pybind11,我试图将一个 numpy 数组传递给 c++ 到 a 中std::vector,将其乘以 2,然后将其std::vector作为 numpy 数组返回给 python。
我已经完成了第一步,但第三步是在做一些奇怪的事情。为了将它传回,我使用了:py::array ret = py::cast(vect_arr);奇怪的是,我的意思是 Python 中返回的向量没有正确的维度和正确的顺序。
例如,我有数组:
[[ 0.78114362 0.06873818 1.00364053 0.93029671]
[ 1.50885413 0.38219005 0.87508337 2.01322396]
[ 2.19912915 2.47706644 1.16032292 -0.39204517]]
Run Code Online (Sandbox Code Playgroud)
代码返回:
array([[ 1.56228724e+000, 3.01770826e+000, 4.39825830e+000,
5.37804299e+161],
[ 1.86059342e+000, 4.02644793e+000, -7.84090347e-001,
1.38298992e-309],
[ 1.75016674e+000, 2.32064585e+000, 0.00000000e+000,
1.01370255e-316]])
Run Code Online (Sandbox Code Playgroud)
我已经阅读了文档,但我必须承认无法理解其中的大部分内容。因此,对于这个具体示例的任何帮助将不胜感激。提前致谢。
这是一个尝试的例子:
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <Python.h>
namespace py = pybind11;
py::module nn = py::module::import("iteration");
py::array nump(py::array arr){
auto arr_obj_prop = …Run Code Online (Sandbox Code Playgroud) 我想用R中的修改参数进行递归函数调用。
recursive_function_call <- function(call) {
fun_call <- as.list(call)
fun <- fun_call[[1]]
arguments <- fun_call[-1]
## Modify Arguments
arguments$drop_option <- NULL
## Call Function
result <- do.call(what = fun, args = arguments)
return(result)
}
recursive_function_call(match.call())
Run Code Online (Sandbox Code Playgroud)
我想从类似函数的数组中调用此函数。如果从顶层函数调用此变量,则该变量fun将为类型symbol,而在底层函数调用该变量,则fun为a function。
我的问题是,do.call()当函数是符号时失败,而对于参数来说可以是符号就失败了。
我的解决方案是将符号转换为字符串。
if (is.symbol(fun_call[[1]])) fun <- as.character(fun_call[[1]]) else fun <- fun_call[[1]]
Run Code Online (Sandbox Code Playgroud)
我需要在图表上添加一个额外的右侧 y 轴。我已经成功地使用下面的代码在 ggplot 中做到了这一点。但该轴的文本方向与主 y 轴的文本方向相反。我被要求使文本方向相同。我已经在 ggplot 帮助和在线中搜索了相关说明,但我找不到任何有关如何控制辅助轴标题方向的信息(勾选标签是,标题否)。
如果有人能告诉我如何做到这一点,我将不胜感激。谢谢。
tbbl <- tibble(ltrs = letters,
nums = rnorm(26)) %>%
mutate(rownum = row_number()) %>%
mutate(colr = factor(.$rownum %% 2, levels = 0:1) )
gx <- ggplot(data = tbbl, aes(x = rownum)) +
geom_col(aes(y = nums, colour = colr, fill = colr)) +
scale_y_continuous(sec.axis = sec_axis(~ . / 4.184,
name = 'Long title that my client finds hard to read if aligned the default way')) +
labs(x = 'title for x axis', …Run Code Online (Sandbox Code Playgroud)