我想要一个像这里包含的数据系列:
http://robjhyndman.com/tsdldata/roberts/beards.dat
...并将其加载到R中的动物园时间序列对象中.没有日期信息表,但它列出了它是常规的,年度的,并且从y = 1866开始.这就是我正在尝试的......
beard <- read.zoo('http://robjhyndman.com/tsdldata/roberts/beards.dat',
header=FALSE,
index.column=0,
start="1866-01-01",
format="%Y",
skip=4)
Run Code Online (Sandbox Code Playgroud)
它主要起作用,但忽略了zooreg的"开始"参数.
所以,我有一个很好的解决方案,读取这个,然后像这样改变索引...
index(beard) <- as.Date(paste(seq(1866,1911, by=1),'-01-01',sep=''), format="%Y-%m-%d")
Run Code Online (Sandbox Code Playgroud)
...但如果有一个论点read.zoo()让我在一次通话中这样做,这将会更加光滑.我错过了,还是两步问题?
根据我在这里收到的建议,我试图在没有无关的绑定分配的情况下重写函数并返回,但是我遇到了额外的IO,我似乎无法理解如何摆脱它.
我有
good :: IO (Either Int String)
getit :: Either Int String -> Int
main :: IO ()
main = do
x <- fmap getit good
putStrLn $ show x
Run Code Online (Sandbox Code Playgroud)
主要工作正常.但....
main2 :: IO ()
main2 = do
putStrLn $ show $ fmap getit good
-- let's try totally without do
main3 :: IO ()
main3 = putStrLn $ fmap show $ fmap getit good
Run Code Online (Sandbox Code Playgroud)
main2失败了:
• No instance for (Show (IO Int)) arising from a use …Run Code Online (Sandbox Code Playgroud) 我正在设置一个小型演示应用程序,我希望现在只能从我的家庭 IP 地址访问,也许我将与一小组技术人员进行协调和分享。
我在这里查看了自述文件,但找不到:https : //github.com/gin-gonic/gin
---关于如何将应用程序的访问限制为 gin 中的特定 IP 地址的规范的、最小的示例是什么?
(另外,有什么理由认为这是 2018 年特别不安全的想法?)
我正在使用以下命令进行屏幕截图:
chromium-browser --headless --screenshot https://www.google.com
Run Code Online (Sandbox Code Playgroud)
从这里。
这基本上可以工作:
[1101/145557.285618:ERROR:gpu_process_transport_factory.cc(980)] Lost UI shared context.
[1101/145558.357174:INFO:headless_shell.cc(538)] Written to file screenshot.png.
Run Code Online (Sandbox Code Playgroud)
(在其他地方对此进行了很好的介绍,但是我没有找到关于“丢失的UI”错误的有用修补程序。这无关紧要。)
如何设置screenshot.png要另存为的名称?
我发现了chrome命令行开关的一些缺陷,例如这个,但是最有可能出现的标志“ --output”与屏幕截图无关。
如果您对无头或无镶边的屏幕截图有更好的建议,就这么简单,那么我很高兴。
如果我有一个简单的Haskell单行程序,那么ghc或ghci中的标志可以从命令行执行此操作吗?
我正在寻找类似的东西:
stack ghci -e 'putStrLn "hello world"'
Run Code Online (Sandbox Code Playgroud)
相近
$ R --quiet -e "cat('hello world')"
> cat('hello world')
hello world>
Run Code Online (Sandbox Code Playgroud)
要么
$ python -c "print('hello world')"
hello world
Run Code Online (Sandbox Code Playgroud)
(这个问题已经通过一个很好的答案得到了解决,但只是调试一下这个标志似乎/应该/在上面工作......)
奇怪的是,无法让看似支持的ghci -e人为我工作.测试它不仅仅是我的机器,我也在Ubuntu上运行它并遇到同样的问题:
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install --yes curl \
&& curl -sSL https://get.haskellstack.org/ | sh \
&& export HOME=/root/.local/bin:$HOME \
&& stack ghci -e 'putStrLn "hello world"'
Run Code Online (Sandbox Code Playgroud)
然后
$ docker build .
Run Code Online (Sandbox Code Playgroud)
产...
Stack has been installed to: /usr/local/bin/stack
WARNING: …Run Code Online (Sandbox Code Playgroud) 我正在尝试将对象序列化为json时重命名键。
我知道这样做的方法是,而不是仅使用派生泛型,而是使用如下自定义键名定义实例:
-- instance ToJSON R2 -- old
instance ToJSON R2 where
toJSON (R2 recCode recDate) = object [ "code" .= recCode , "date" .= recDate ]
-- new
Run Code Online (Sandbox Code Playgroud)
但是,这给了我:
<interactive>:2:70: error:
Ambiguous occurrence ‘.=’
It could refer to either ‘Data.Aeson..=’, imported from ‘Data.Aeson’ (and originally defined in ‘aeson-1.3.1.1:Data.Aeson.Types.ToJSON’)
or ‘Control.Lens..=’, imported from ‘Control.Lens’ (and originally defined in ‘Control.Lens.Setter’)
Run Code Online (Sandbox Code Playgroud)
我试图解决此问题的方法是.=通过在我的代码中定义操作符来显式强制其含义,例如:
(.=) = Data.Aeson.(.=)
Run Code Online (Sandbox Code Playgroud)
这是一个猜测,但似乎语法错误。我将类推类推添加到以下资源中:
这给了我这个错误:
(.=) = Data.Aeson (.=)
<interactive>:1:8: error:
Not in scope: data …Run Code Online (Sandbox Code Playgroud) 我有以下代码用于基于此处结合不同端点的 Sanic hello world:
代码是:
from sanic import Sanic
from sanic import response
from sanic.websocket import WebSocketProtocol
app = Sanic()
@app.route("/")
async def test(request):
return response.json({"hello": "world"})
@app.route('/html')
async def handle_request(request):
return response.html('<p>Hello world!</p>')
@app.websocket('/feed')
async def feed(request, ws):
while True:
data = 'hello!'
print('Sending: ' + data)
await ws.send(data)
data = await ws.recv()
print('Received: ' + data)
@app.route('/html2')
async def handle_request(request):
return response.html("""<html><head><script>
var exampleSocket = new WebSocket("wss://0.0.0.0:8000/feed", "protocolOne");
exampleSocket.onmessage = function (event) {
console.log(event.data)};</script></head><body><h1>Hello socket!</h1><p>hello</p></body></html>""")
app.run(host="0.0.0.0", …Run Code Online (Sandbox Code Playgroud) 这里有一个关于原始 boto 上传的很好的问题和答案:
其中有一个回调:
k = Key(bucket)
k.key = 'my test file'
k.set_contents_from_filename(testfile,
cb=percent_cb, num_cb=10)
Run Code Online (Sandbox Code Playgroud)
虽然我看到 boto3 包需要回调:
我没有看到与 num_cb 参数等效的内容。如何获得upload_fileobj使用 boto3 的进度表?
s3.upload_fileobj(data, 'mybucket', 'mykey')
Run Code Online (Sandbox Code Playgroud) 我正在寻找使用维基数据按人口重新创建德克萨斯州城市列表。
我看到我可以用这个查询按人口做状态:
SELECT DISTINCT ?state ?stateLabel ?population
{
?state wdt:P31 wd:Q35657 ;
wdt:P1082 ?population .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?state ?population ?stateLabel
ORDER BY DESC(?population)
Run Code Online (Sandbox Code Playgroud)
德克萨斯州的 id 是 wd:Q1439
所以我尝试了以下方法:
SELECT ?country ?countryLabel ?state ?stateLabel ?city ?cityLabel ?population
WHERE
{
# ?state wdt:P31 wd:Q35657 . # Give me an american state
?state wdt:P31 wd:Q1439 . # that state is is Texas
?city wdt:P31 wd:Q515 . # it is …Run Code Online (Sandbox Code Playgroud) 我试图将指数衰减线(带有误差线)绘制到价格信息的ggplot中的散点图上.我目前有这个:
f2 <- ggplot(data, aes(x=date, y=cost) ) +
geom_point(aes(y = cost), colour="red", size=2) +
geom_smooth(se=T, method="lm", formula=y~x) +
# geom_smooth(se=T) +
theme_bw() +
xlab("Time") +
scale_y_log10("Price over time") +
opts(title="The Falling Price over time")
print(f2)
Run Code Online (Sandbox Code Playgroud)
关键是在geom_smooth命令中,formula=y~x 尽管这看起来像一个线性模型,ggplot似乎会自动检测我的scale_y_log10并记录它.
现在,我的问题是日期是日期数据类型.我想我需要将它转换为秒,因为t = 0才能应用表格的指数衰减模型y = Ae^-(bx).
我相信这是因为当我尝试y = exp(x)之类的东西时,我得到一条消息,我认为(?)告诉我,我不能接受日期的指数.它写道:
Error in lm.wfit(x, y, w, offset = offset, singular.ok = singular.ok, :
NA/NaN/Inf in foreign function call (arg 1)
但是,log(y) = x正常工作.(y是数字数据类型,x是日期.)
有没有一种方便的方法可以在geom_smooth(公式=公式)函数调用中的ggplot图中拟合指数增长/衰减时间序列模型?