我有一个具体的问题.我想卖掉我用R编程语言编写的一个模型.我想向潜在客户展示代码中有很多高级工作,并且有很多代表大约700小时的研发(大约2000行R代码).所以,我想给他发送代码.给他留下深刻印象.
但是我显然不想透露代码的全部工作原理,所以我想考虑每三分之一或四行,所以它不能简单地进行OCR和复制.我不想走NDA路线,客户也不擅长编程(不能自己复制它 - 虽然我可以聘请程序员).我也可能完全搞砸一两个关键功能.
我怎么在Vi/Vim做这个?
有没有其他方法可以解决我的问题?
是的,我知道我可以向他展示该计划的输出作为我已经完成的销售宣传,但是我们正在通过代码清单讨价还价"科学致盲",看看有多少工作是参与,不会受伤.根据我的经验,许多非程序员不知道可以在一个软件中进行多少工作.
我有21个全局环境变量,每个变量都包含大量数据.我希望通过函数内的引用来访问这些变量,但我想对它们的名称进行参数化,例如,如果我有SPdata,NEdata,FRdata等...... 21个变量,我想知道如何通过传递在函数内访问它们只需要"国家名称"(即"SP","NE","FR"等)而不必创建副本(因为它们的大小都超过300微米).似乎可以制作副本(对于我的大小效率低)数据).我可以这样做吗?我目前正在使用无处不在
cData <- get(paste(cCode, "data", sep = ""))
Run Code Online (Sandbox Code Playgroud)
是的我知道我应该将它们全部放入全局环境中的列表中,但现在已经太晚了,我不想重构所有代码.只是我的"获取"变得内存效率低下,循环中的多次访问可能会很慢.例如,我可以像访问列表一样访问每个变量吗?
我应该使用countryData = list(SPdata,NEdata,FRdata..etc),使用countryData [[paste(cCode,"data",sep ="")]来访问它们,但现在已经太晚了.
我应该补充一点,我确实打算在函数中更改一些值,并且get()会在更改时进行复制,这可以从下面的不同地址中看到.
> .Internal(inspect(a))
@101b7bcf8 14 REALSXP g0c1 [NAM(2)] (len=1, tl=0) 1
> g <- function() {x <- get("a"); x; x <- 2; .Internal(inspect(x))}
> g()
@101cea648 14 REALSXP g0c1 [NAM(2)] (len=1, tl=0) 2
>
Run Code Online (Sandbox Code Playgroud) GGplot2 scale_colour_gradient在绘图中使用两次时打印出警告,我无法在knitr中抑制.以下是编辑RHTML文件后浏览器的屏幕截图:

我需要着色渐变,一个用于线条(便宜/亲爱的屈服曲线)和一个用于相似但略微不同的乐器(彩色圆点).
这是我的ggplot代码:
ggp <- ggplot(polys, aes(x = xvals, y = yvals)) +
#geom_polygon(aes(fill = - value, group = id, alpha = value)) + # lovely blue
geom_polygon(aes(fill = value, group = id, alpha = value)) + # lovely shiny light blue middle draw me in
scale_x_log10(breaks = xaxtickpos, minor_breaks = NULL) +
theme(legend.position = "none", panel.background = element_rect(fill = "grey85", colour = NA)) +
xlab("maturity") + ylab("bps")
ggp <- ggp + geom_line(data = quanmelt[quanmelt[, "percentile"] %in% outerthresh, …Run Code Online (Sandbox Code Playgroud) 如何在单个Elixir中编码多个语句以接收模式匹配?
这有效:
def pong sender do
receive do
x -> IO.puts("hello"); IO.puts("there"); send(sender, x)
end
end
Run Code Online (Sandbox Code Playgroud)
但是,如果我不能将它们全部放在同一行怎么办?可以使用do end子句将它们括起来吗?因为这不起作用:
def pong sender do
receive do
x -> do
IO.puts("hello")
IO.puts("there")
send(sender, x)
end
end
end
Run Code Online (Sandbox Code Playgroud) 因此,我可以根据参数的类型使用保护子句来运行函数的不同版本:
iex(2)> defmodule Test do
...(2)>
...(2)> def double(x) when is_integer(x) do
...(2)> x * 2
...(2)> end
...(2)>
...(2)> def double(x) when is_binary(x) do
...(2)> String.to_integer(x) * 2
...(2)> end
...(2)> end
iex(3)> Test.double(2)
4
iex(4)> Test.double("2")
4
Run Code Online (Sandbox Code Playgroud)
但是,如果我想基于Timex.Datetime类型放置保护子句,例如:
iex(5)> Timex.now
#DateTime<2018-03-16 12:36:24.061549Z>
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到Timex.is_datetime函数或等效函数。
如何使用Numpy或Pandas进行R(xts)等效rollapply(....,by.column = FALSE)?给定数据帧时,pandas rolling_apply似乎只能逐列工作,而不是提供向目标函数提供完整(窗口大小)x(数据帧宽度)矩阵的选项.
import pandas as pd
import numpy as np
xx = pd.DataFrame(np.zeros([10, 10]))
pd.rolling_apply(xx, 5, lambda x: np.shape(x)[0])
0 1 2 3 4 5 6 7 8 9
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 5 5 5 5 …Run Code Online (Sandbox Code Playgroud) 我已经成功地在Pymongo使用了2年的tailable游标,但突然间,今天,我的相同代码抛出了"意外的关键字"错误:

我几周前升级到3.0 Mongo并且它仍然工作正常,但是现在可能是一个新的pymongo版本,因为我今天刚刚安装了新版本(3.0.1)?以前是pymongo 2.6.3.我的代码:
cursor = refreq.find(tailable = True, await_data = True)
while cursor.alive:
xxx
Run Code Online (Sandbox Code Playgroud)
所以基本上任何时候插入refreq集合的东西我想知道它,没有轮询.习惯工作正常.最近安装了Pymongo 3.0.1版(今天).
试图插入一个空的字典
cursor = refreq.find({}, tailable = True, await_data = True)
Run Code Online (Sandbox Code Playgroud)
但仍然给出相同的错误.有什么变化?
这是完整的线程代码,供参考:
def handleRefRequests(db, refqueue):
""" handles reference data requests. It's threaded. Needs the database id.
will create a capped collection and constantly poll it for new requests"""
print("Dropping the reference requests collection")
db.drop_collection("bbrefrequests")
print("Recreating the reference requests collection")
db.create_collection("bbrefrequests", capped = True, size = 100 * 1000000) # x * megabytes
refreq …Run Code Online (Sandbox Code Playgroud) 为什么这不起作用:
iex(2)> Enum.map(["the", "huge", "elephant"], String.length)
** (UndefinedFunctionError) function String.length/0 is undefined or private.
Run Code Online (Sandbox Code Playgroud)
但这样做:
iex(2)> Enum.map(["the", "huge", "elephant"], fn x -> String.length(x) end)
[3, 4, 8]
Run Code Online (Sandbox Code Playgroud)
我的意思是,String.length是一个函数,对吗?就像我的匿名包装一样?或者是根据错误消息的某种范围问题?
我对另一种功能(ish)语言的唯一体验是R,这样可以正常工作:
> sapply(c("the", "huge", "elephant"), nchar)
the huge elephant
3 4 8
> sapply(c("the", "huge", "elephant"), function(x) nchar(x))
the huge elephant
3 4 8
Run Code Online (Sandbox Code Playgroud) 我是Javascript的新手,并尝试将事件处理程序附加到选择列表.这是我的HTML:
<select id="x_selector"></select>
Run Code Online (Sandbox Code Playgroud)
我正在成功添加一堆选项.但是我想添加一个on change方法.这个jquery javascript工作原理:
let xsel = $("#x_selector");
xsel.on("change", event => {console.log(event)});
Run Code Online (Sandbox Code Playgroud)
但这不是:
var xSelector = document.getElementById('x_selector');
xSelector.on("change", event => {console.log(event)});
Run Code Online (Sandbox Code Playgroud)
对于后一个我得到一个控制台TypeError:xSelector.on不是一个函数.
那么document.getElementById和jquery选择器之间有什么区别?
我知道 怎么放,获取和使用更新药剂嵌套地图put_in,get_in以及update_in,但我怎么“ delete_in“?
假设我有此嵌套地图,并且想删除键:c及其关联的值。
iex(1)> mymap = %{:a => %{:b => 1, :c => 2}}
%{a: %{b: 1, c: 2}}
Run Code Online (Sandbox Code Playgroud)
我如何有效地回到这一点?
{%a: %{b: 1}}
Run Code Online (Sandbox Code Playgroud) 在 Elixir 的列表映射中查找与最小长度列表关联的键的有效方法是什么。假设我有:
z = %{a: [1, 2, 3], b: [4, 5], c: [6, 7, 8, 9]}
Run Code Online (Sandbox Code Playgroud)
我知道我能做到:
Enum.map z, fn {k, v} -> length(v) end
Run Code Online (Sandbox Code Playgroud)
这会给我:
[3, 2, 4]
Run Code Online (Sandbox Code Playgroud)
但我真正需要的只是答案,即与最小值 2 相关的键,当然是:b。
我将大约每秒在列表的动态映射上运行它,所以我希望它尽可能高效。
假设我在Elixir中有一个严格增加整数的列表,我想在数字大于5的倍数时分解为子列表.我正在尝试使用chunk_by但是我得到了这个:
Enum.chunk_by([300, 301, 304, 305, 306, 309, 310, 311, 312, 313, 314,
315, 316, 317, 319, 320], fn(x) -> rem(x, 5) == 0 end)
[
[300],
[301, 304],
[305],
[306, 309],
[310],
[311, 312, 313, 314],
[315],
[316, 317, 319],
[320]
]
Run Code Online (Sandbox Code Playgroud)
当我真正想要的是:
[
[300, 301, 304],
[305, 306, 309],
[310, 311, 312, 313, 314],
[315, 316, 317, 319],
[320]
]
Run Code Online (Sandbox Code Playgroud)
我基本上需要在"5边界"上分解的列表,但没有边界本身创建单独的列表.我该怎么做?