我正在尝试缓冲半径为100km的数据集中的点.我正在使用gBuffer包中的功能rgeos.这是我到目前为止所拥有的:
head( sampledf )
# postalcode lat lon city province
#1 A0A0A0 47.05564 -53.20198 Gander NL
#4 A0A1C0 47.31741 -52.81218 St. John's NL
coordinates( sampledf ) <- c( "lon", "lat" )
proj4string( sampledf ) <- CRS( "+proj=longlat +datum=WGS84" )
distInMeters <- 1000
pc100km <- gBuffer( sampledf, width=100*distInMeters, byid=TRUE )
Run Code Online (Sandbox Code Playgroud)
我收到以下警告:
在gBuffer中(sampledf,width = 100*distInMeters,byid = TRUE):不投影空间对象; GEOS期望平面坐标
根据我的理解/阅读,我需要将数据集的坐标参照系(CRS),特别是投影从"地理"更改为"预测".我不确定如何改变它.这些都是加拿大的地址,我可以补充一下.所以NAD83在我看来是一个自然的选择,但我可能错了.
任何/所有帮助将不胜感激.
问题是关于朱莉娅的"最佳实践".我读过这个和这个.我有一个功能
function discount_rate(n, fv, pmt, pv; pmt_type = 0)
...
end
Run Code Online (Sandbox Code Playgroud)
现在的问题是我必须像这样调用方法
discount_rate( 10, 10, 10, -10 )
Run Code Online (Sandbox Code Playgroud)
目前尚不清楚这些论点意味着什么 - 即使我忘了.我喜欢做的就是写作
discount_rate( n = 10, fv = 10, pmt = 10, pv = -10 )
Run Code Online (Sandbox Code Playgroud)
这更清楚:更容易阅读和理解.但我无法通过创建这些参数keywords参数或optional参数来定义我的方法,因为它们没有自然默认值.从设计的角度来看,有推荐的解决方法吗?
我有python正则表达式对象 - 比如,re_first和re_second - 我想连接.
import re
FLAGS_TO_USE = re.VERBOSE | re.IGNORECASE
re_first = re.compile( r"""abc #Some comments here """, FLAGS_TO_USE )
re_second = re.compile( r"""def #More comments here """, FLAGS_TO_USE )
Run Code Online (Sandbox Code Playgroud)
我想要一个与上述正则表达式中的任何一个匹配的正则表达式.到目前为止,我有
pattern_combined = re_first.pattern + '|' + re_second.pattern
re_combined = re.compile( pattern_combined, FLAGS_TO_USE )
Run Code Online (Sandbox Code Playgroud)
对于更多的python对象,这不能很好地扩展.我最终看起来像:
pattern_combined = '|'.join( [ first.pattern, second.pattern, third.pattern, etc ] )
Run Code Online (Sandbox Code Playgroud)
关键是要连接的列表可能很长.任何想法如何避免这种混乱?提前致谢.
我试图重构这个.在Python中,我会使用装饰器.什么是'糟糕的方式来做到这一点?说,我们有这种模式
good_input <- format_input( bad_input )
bad_output <- use_this_func( good_input )
good_output <- format_output( bad_output )
Run Code Online (Sandbox Code Playgroud)
然后,
good_input <- format_input( bad_input )
bad_output <- use_this_other_func( good_input )
good_output <- format_output( bad_output )
Run Code Online (Sandbox Code Playgroud)
你可以想象,它会像野生蘑菇一样繁殖.我想要接近这个解决方案
use_this_robust_func <- wrapper( use_this_func ) # Or wrapper( use_this_other_func )
good_output <- use_this_robust_func( bad_input )
Run Code Online (Sandbox Code Playgroud)
我试图总结调用use_this_func和use_this_other_func使用(和相关函数)format_input和format_output.到目前为止,我已经部分地使用了这个问题
wrapper <- function( func_not_robust ){
func_robust <- function( ... ){
# This is the bit I haven't figured out
... format_input( ) …Run Code Online (Sandbox Code Playgroud) 我在我自己的模块上使用GNU gfortran编译器(在Cygwin上).一个很好的例子将有希望从编译阶段开始,解决损坏的名称并从Julia中调用子例程ccall.我见过的大多数例子都跳过前两个阶段.
所以想象一下,我在Fortran 90文件中有以下模块名为'f90tojl.f90':
module m
contains
integer function five()
five = 5
end function five
end module m
Run Code Online (Sandbox Code Playgroud)
这个例子来自这里.我用gfortran编译它如下创建一个共享库:
gfortran -shared -O2 f90tojl.f90 -o -fPIC f90tojl.so
Run Code Online (Sandbox Code Playgroud)
而且,通过阅读朱莉娅文档,我的,理所当然的不稳定的理解表明,我应该能够像这样调用函数五:
ccall( (:__m_MOD_five, "f90tojl"), Int, () )
Run Code Online (Sandbox Code Playgroud)
它对我不起作用.我得到'error compiling anonymous: could not load module f90tojl....有人关心开导我吗?我有一种偷偷摸摸的感觉,我正在做些傻事......
在官方文档中,重点是C.我也知道C++ 的这个.在R和Python中,动力 - 我想到了Cython和Rcpp--似乎是C/C++.与此问题类似,我想了解使用C/C++将Julia与Fortran与Julia联系起来是多么容易.
我正在尝试从Julia中的数组中抽取n个(例如,为简单起见,为10个)。使用下面的功能wsample,ndraws我可以得到想要的
using Distributions
population = [ 1, 10 ]
weights = [ .4, .6 ]
population_idx = wsample( population, weights, 10 ) # i.e. population indices
ndraws = population[ population_idx ]
Run Code Online (Sandbox Code Playgroud)
我正在使用Julia 0.2。没有索引,有没有办法做同样的事情?在R比如,我们有
ndraws <- sample( population, size = 10, replace = TRUE, prob = weights )
Run Code Online (Sandbox Code Playgroud)
这里的文档建议有这样做
ndraws = wsample( population, weights, 10 )
Run Code Online (Sandbox Code Playgroud)
应该给我,嗯,正是我想要的?还要注意,在docs中,平局次数的参数名称是,n但在的源代码中查找时sample.jl,它是指k。