这有效:
struct Comic
endpoint::String
end
function Comic(id::Int)
url = "https://xkcd.com/$id/info.0.json"
Comic(url)
end
Comic(1)
Run Code Online (Sandbox Code Playgroud)
它返回Comic("https://xkcd.com/1/info.0.json")。
这不起作用:
struct Comic
endpoint::String
end
function Comic(id::String)
url = "https://xkcd.com/$id/info.0.json"
Comic(url)
end
Comic("1")
Run Code Online (Sandbox Code Playgroud)
它杀死了 Julia 进程。
为什么第二个例子不起作用?
我正在尝试重新排列 DataFrame 中的列,首先放置几列,然后放置所有其他列。
使用 R's dplyr,这看起来像:
library(dplyr)
df = tibble(col1 = c("a", "b", "c"),
id = c(1, 2, 3),
col2 = c(2, 4, 6),
date = c("1 Feb", "2 Feb", "3 Feb"))
df2 = select(df,
id, date, everything())
Run Code Online (Sandbox Code Playgroud)
简单。使用 Python's pandas,这是我尝试过的:
import pandas as pd
df = pd.DataFrame({
"col1": ["a", "b", "c"],
"id": [1, 2, 3],
"col2": [2, 4, 6],
"date": ["1 Feb", "2 Feb", "3 Feb"]
})
# using sets
cols = df.columns.tolist()
cols_1st = {"id", "date"} …Run Code Online (Sandbox Code Playgroud) 我在conda 文档、 教程和 书籍中看到过这样的说法 。不要在基础环境中安装程序。创建一个单独的环境并在其中安装您想要的任何软件包/程序。但从未解释过原因。我想这是因为介绍材料不想让初学者感到困惑。那么让我们在这里这样做吧。
为什么不应在其基本环境中安装额外的软件包?会发生什么?有哪些风险?
最后,基础环境的目的是什么?我应该如何使用它?到底有什么好处呢?
我正在使用 knit + Rmarkdown 创建 PDF 文档。我已经geometry: margin=0.1in在 yaml 标头中设置了。此边距适用于文档的正文,但标题距离文档顶部以及正文都相当远。这是一个屏幕截图:
下面是在屏幕截图中创建文档的 Rmd 代码:
---
title: "test"
output:
pdf_document:
latex_engine: xelatex
geometry: margin=0.1in
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
a bunch of text to demonstrate that the margin applies only to the body text of
this document, while the title (above) remains quite far from the top of the
document, and this is messing up my plan to make a document that's only one page
in length …Run Code Online (Sandbox Code Playgroud) 标题很复杂,但我不知道如何用语言表达这个问题。所以我会演示一下。
这是我的问题,具有所需的输出:
library(tibble)
# Input:
tribble(
~n_1, ~n_2, ~n_3, ~pct_1, ~pct_2, ~pct_3,
10, 20, 30, 0.1, 0.2, 0.3
)
#> # A tibble: 1 x 6
#> n_1 n_2 n_3 pct_1 pct_2 pct_3
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 10 20 30 0.1 0.2 0.3
# Desired output:
tribble(
~name, ~n, ~pct,
1, 10, 0.1,
2, 20, 0.2,
3, 30, 0.3
)
#> # A tibble: 3 x 3
#> name n pct
#> <dbl> <dbl> <dbl> …Run Code Online (Sandbox Code Playgroud) 假设我有 3 个 DataFrame。其中一个 DataFrame 的列名不在其他两个 DataFrame 中。
using DataFrames
df1 = DataFrame([['a', 'b', 'c'], [1, 2, 3]], ["name", "id"])
df2 = DataFrame([['d', 'e', 'f'], [4, 5, 6]], ["name", "id"])
df3 = DataFrame([['x', 'y', 'z'], [7, 8, 9], [11, 22, 33]], ["name", "id", "num"])
Run Code Online (Sandbox Code Playgroud)
每个 DataFrame 都是 Vector 的一个元素。
dfs = [df1, df2, df3]
Run Code Online (Sandbox Code Playgroud)
我想将所有这些 DataFrame 组合成一个大 DataFrame。这是我尝试过的:
df = reduce(x -> vcat(x, cols=:union), dfs)
# MethodError: no method matching (::var"#55#56")(::DataFrame, ::DataFrame)
Run Code Online (Sandbox Code Playgroud)
那么,我该如何在 Julia 中做到这一点呢?
加分点:我可以在没有 DataFrames.jl 的基础 Julia 中执行此操作(注意: …
我运行以下命令:
library(dplyr)
library(sf)
library(tigris)
library(tmap)
options(tigris_class = 'sf')
options(tigris_use_cache = TRUE)
nj = tigris::states(cb = T, year = 2015) %>%
filter(STUSPS == 'NJ')
nj_msas = tigris::core_based_statistical_areas(cb = T, year = 2015) %>%
filter(grepl('NJ', NAME)) %>%
sf::st_intersection(nj)
tmap_mode('plot')
nj_msas %>%
tm_shape() +
tm_polygons()
Run Code Online (Sandbox Code Playgroud)
最后一个块给出了错误:
vapply(g2, st_is_empty, logical(1)) 中的错误:值长度必须为 1,但 FUN(X[[3]]) 结果长度为 148
当我删除 时st_intersection,最后一个块没有错误。我无法通过谷歌搜索在任何地方找到此错误消息。有谁知道发生了什么?
另外,如果我运行除最后一个块之外的所有上述内容,并且我ggplot2::geom_sf用来创建地图而不是tmap函数,我会得到我想要的地图。没有错误。
我正在使用 Ubuntu 18.04.1。RStudio v1.1.463。R 3.5.2。底格里斯河 0.7。地图 2.2。平方英尺 0.7-2。