我正在从R移动,我经常使用头()功能。我在Julia中找不到类似的方法,所以我为Julia数组编写了一个方法。还有几个其他的R函数,我也要移植到Julia。
我需要这些方法可以在启动的每个Julia实例中使用,无论是通过IJulia还是通过命令行。朱莉娅有什么“启动脚本”吗?我怎样才能做到这一点?
PS:如果有人感兴趣,这就是我写的。一般用途还需要做很多工作,但它做了我现在需要做的事情。
function head(obj::Array; nrows=5, ncols=size(obj)[2])
if (size(obj)[1] < nrows)
println("WARNING: nrows is greater than actual number of rows in the obj Array.")
nrows = size(obj)[1]
end
obj[[1:nrows], [1:ncols]]
end发布于 2014-08-16 03:23:12
您可以创建一个~/.juliarc.jl文件,请参阅手册的快速入门部分。
至于您的head函数,下面是我如何实现它的方法:
function head(obj::Array; nrows=5, ncols=size(obj,2))
if size(obj,1) < nrows
warn("nrows is greater than actual number of rows in the obj Array.")
nrows = size(obj,1)
end
obj[1:nrows, 1:ncols]
endhttps://stackoverflow.com/questions/25336490
复制相似问题