import os
for dirpaths, dirnames, filenames in os.walk(mydir):
print dirpaths
Run Code Online (Sandbox Code Playgroud)
给我所有(子)目录mydir.如何只获取树底部的目录?
我正在sf使用 绘制(映射)对象ggplot2。我的理解是,由于版本 2.2.1ggplot2包含 geom geom_sf,用于简单的特征对象。
我可以通过执行以下操作来生成我想要的精确地图:
library(sf)
library(ggplot2)
# some points to start with
a <- st_as_sf(data.frame(lon = c(1,4,6), lat = c(0,0,-3)), coords = c('lon', 'lat'))
b <- st_as_sf(data.frame(lon = c(2.5,4), lat = c(-4.5,-5)), coords = c('lon', 'lat'))
# circles around those points
buf.a <- st_buffer(a, 1)
buf.b <- st_buffer(b, 1)
# colors to mark the points
sol.a = rgb(1,0,0)
sol.b = rgb(0,0,1)
# colors to fill the circles
fil.a = adjustcolor(sol.a, alpha.f …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行两个数据表的笛卡尔连接。因为我的表很大(10 Gb),所以我需要以内存高效的方式执行此操作。所以我想我会以一种以 - 为中心的方式通过引用更新其中一个表data.table。
这就是我想要实现的目标:
# fake data
A = data.table(id = c(1, 1, 1, 2, 2, 3),
X = 0:5,
Y = letters[1:6],
key = 'id')
B = data.table(id = rep(1:3, each = 3) ,
time = rep(1:3, 3),
Z = 8:0,
key = c('id', 'time'))
# the desired join: cartesian join with columns from both tables
B[A, on = 'id', allow.cartesian = T]
Run Code Online (Sandbox Code Playgroud)
但是,此解决方案中没有更新任何表。出于内存原因,我想避免创建第三个表。
如何通过引用更新其中一个表(A或B)来实现此目的?
部分受到这个问题答案的启发,这是我尝试过但没有成功的方法:
# table B gets the …Run Code Online (Sandbox Code Playgroud) 我已经从package切换sp到sf了我的许多地理位置R,直到现在我才发现sp/中有奇怪的行为rgeos。这里是:
library(sp)
library(sf)
library(rgeos)
# crs
WGS84M = "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
# a point
point = data.frame(x = 0, y = 0)
# simple feature from point
f.point = st_as_sf(point, coords = c('x', 'y'))
st_crs(f.point) = WGS84M
f.buf = st_geometry(st_buffer(f.point, dist = 5 * 1000))
# spatial object from point
s.point = SpatialPoints(point, proj4string = CRS(WGS84M))
s.buf = gBuffer(s.point, width = 5 * 1000)
plot(s.buf, …Run Code Online (Sandbox Code Playgroud) 我试图理解为什么
foo = function(d,y,x) {
fit = with(d, lm(y ~ x))
}
foo(myData, Y, X)
Run Code Online (Sandbox Code Playgroud)
不起作用,例如
myData = data.frame(Y=rnorm(50), X=runif(50))
Run Code Online (Sandbox Code Playgroud)
对我来说,棘手的一点是将参数x和传递y给公式,如 中所示lm(y ~ x)。