小编Liz*_*ung的帖子

如何使用quantmod包从R中的data.frame中提取行索引

使用quantmod包,我正在提取库存数据,如下所示

library(quantmod)
getSymbols('F')
head(F)
Run Code Online (Sandbox Code Playgroud)

它给出了输出

           F.Open F.High F.Low F.Close F.Volume
2007-01-03   7.56   7.67  7.44    7.51 78671500
2007-01-04   7.56   7.72  7.43    7.70 63545800
2007-01-05   7.72   7.75  7.57    7.62 40563800
2007-01-08   7.63   7.75  7.62    7.73 48941200
2007-01-09   7.75   7.86  7.73    7.79 56732500
2007-01-10   7.79   7.79  7.67    7.73 42398600
# and an unimportant(here) warning regarding download length
Run Code Online (Sandbox Code Playgroud)

我希望能够在这里提取明显的日期列,并将数据作为data.frame使用,通常我会尝试查找列名并拉出该列,但日期不包含在列中!

r quantmod

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

背包算法仅限于N元素解

这个来自adagio函数knapsack()的CRAN文档的摘录按预期运行 - 它解决了利润向量p,权重向量w和容量的背包问题cap,选择具有最大利润的元素子集受限于总权重选定的元素不超过容量.

library(adagio)
p <- c(15, 100, 90, 60, 40, 15, 10,  1)
w <- c( 2,  20, 20, 30, 40, 30, 60, 10)
cap <- 102
(is <- knapsack(w, p, cap))
Run Code Online (Sandbox Code Playgroud)

如何向解决方案添加矢量长度约束并仍然获得最佳答案?例如,上面的练习,但选定的子集必须包含正好三个元素.

r knapsack-problem mathematical-optimization

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

R 在空行上分割文本

我有一个很长的文件,如下所示:

"Ach! Hans, Run!" 
2RRGG
Enchantment
At the beginning of your upkeep, you may say "Ach! Hans, run! It's the . . ." and name a creature card. If you do, search your library for the named card, put it into play, then shuffle your library. That creature has haste. Remove it from the game at end of turn.
UNH-R

A Display of My Dark Power
Scheme
When you set this scheme in motion, until your next turn, whenever a …
Run Code Online (Sandbox Code Playgroud)

r

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