小编And*_*man的帖子

dplyr group by,将前一组的值转发到下一组

好的,这是我想用dplyr实现的全部视图:

例

使用dplyr我正在进行计算以形成新列.

initial.capital - 
x.long.shares - 
x.end.value - 
x.net.profit - 
new.initial.capital
Run Code Online (Sandbox Code Playgroud)

执行此操作的代码:

# Calculate Share Prices For Each ETF 
# Initialize Start Capital Column 
library(dplyr)
library(data.table)
df$inital.capital <- 10000
output <- df %>%
  dplyr::mutate(RunID = data.table::rleid(x.long)) %>%
  group_by(RunID) %>%
  dplyr::mutate(x.long.shares = ifelse(x.long == 0,0, 
                                       ifelse(row_number() == n(),
                                      first(inital.capital) / first(close.x),0))) %>%
  dplyr::mutate(x.end.value = ifelse(x.long == 0,0, 
                                       ifelse(row_number() == n(),
                                              last(x.long.shares) * last(close.x),0))) %>%
  dplyr::mutate(x.net.profit = ifelse(x.long == 0,0, 
                                     ifelse(row_number() == n(),
                                            last(initial.capital) - last(x.end.value),0))) %>%
  dplyr::mutate(new.initial.capital = ifelse(x.long == 0,0, …
Run Code Online (Sandbox Code Playgroud)

r dplyr data.table

9
推荐指数
1
解决办法
1340
查看次数

重命名 Dataframe 列名 julia v1.0

在 0.6 我使用的是:

colnames = ["Date_Time","Date_index","Time_index"]
names!(data1_date_time_index.colindex, map(parse, colnames))
Run Code Online (Sandbox Code Playgroud)

v1.0 的语法是什么 - 现在没有找到 .colindex。

每个 DataFrames 文档:

rename!(data1_date_time_index, f => t for (f, t) =
   zip([:x1, :x1_1, :x1_2],     
       [:Date_Time, :Date_index, :Time_index]))
Run Code Online (Sandbox Code Playgroud)

dataframe julia

6
推荐指数
2
解决办法
7580
查看次数

按第一列对 22x2 数组进行排序

我有以下几点:

one = [0.3, 0.3, 0.3, 0.3, 0.3, 0.17, 0.255, 0.1, 0.145, 0.275, 0.17, 0.225, 0.25, 0.25, 0.28, 0.29, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
two = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0]
data_needed = [one two] # build 22×2 Array{Float64,2}
Run Code Online (Sandbox Code Playgroud)

例如输出(截断)

22×2 Array{Float64,2}:
 0.3     0.5
 0.3     1.0
 0.3     1.5
 0.3     2.0
 0.3     2.5
 0.17    3.0
 0.255   3.5
 0.1     4.0
 0.145   4.5
 0.275   5.0 …
Run Code Online (Sandbox Code Playgroud)

julia

3
推荐指数
1
解决办法
87
查看次数

TWS API Linux - 分段错误 - __bid64_to_string

开箱即用地运行 Cpp 示例客户端。

\n

我收到分段错误。

\n

0x00005555555efba6 in __bid64_to_string ()

\n

已将此函数来源到客户端文件Decimal.h

\n

extern "C" void __bid64_to_string(char*, Decimal, unsigned int*);

\n

这可能与API文档提到的浮点库有关:Intel\xc2\xae Decimal Floating-Point Math Library

\n

https://interactivebrokers.github.io/tws-api/introduction.html

\n

我已经使用 WSL Ubuntu 20.04.05 检查了它是否安装在我的 ubuntu 版本上

\n
libintelrdfpmath-dev/now 2.0u2-4 amd64 [installed,local]\n\nroot@flare9x:~# dpkg -s libintelrdfpmath-dev\nPackage: libintelrdfpmath-dev\nStatus: install ok installed\nPriority: optional\nSection: libdevel\nInstalled-Size: 72286\nMaintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>\nArchitecture: amd64\nSource: intelrdfpmath\nVersion: 2.0u2-4\nDescription: Intel Decimal Floating-Point Math Library\n Software implementation of the IEEE 754-2008 Decimal Floating-Point\n Arithmetic specification, aimed at financial applications, especially\n in cases …
Run Code Online (Sandbox Code Playgroud)

c++ linux gcc c++11

2
推荐指数
1
解决办法
698
查看次数

C++ 上的数学输出(对照其他语言进行检查)

我用 C++ 写这个:

int main()
{
    cout<<"print "<< int(((float(979430543) - float(800445804))/2.0)+.5);
}

for output: 89492352
Run Code Online (Sandbox Code Playgroud)

并检查 Julia 语言:

print(Int64(((Float64(979430543) - Float64(800445804))/2.0)+.5))
89492370
Run Code Online (Sandbox Code Playgroud)

结果之间的差异是 18 - 我错过了什么?

c++ julia

1
推荐指数
2
解决办法
103
查看次数

log()负数抛出域错误

我正在尝试在我正在编写的脚本中广播日志功能.

它正在抛出一个域错误

julia> log(100)
4.605170185988092

julia> log(-100)
ERROR: DomainError:
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题?我的数组中混合了 - ,+.

julia

0
推荐指数
1
解决办法
103
查看次数

标签 统计

julia ×4

c++ ×2

c++11 ×1

data.table ×1

dataframe ×1

dplyr ×1

gcc ×1

linux ×1

r ×1