如何使用Cl()与字符?

时间:2017-02-15 07:17:04

标签: r xts quantmod

我在csv文件中有一个符号列表,我想筛选收盘价高于5的那些符号。

我已经为csv文件中的所有项目运行了getSymbols。

我的测试在这里遇到错误。我认为这是因为Cl()不接受字符作为参数。如何将字符转换为xts?

foreach ($faqdata as $key=>$value) {
     if (($key!='id') && ($value!='') {
     $outputarray[]="{'tc':'$value'}";
     } 
}
$output=implode(',',$outputarray);
$output='['.$output.']';

1 个答案:

答案 0 :(得分:1)

无需循环! 假设您已经阅读了上面提到的getSymbols的价格序列,那么:

# an example set of tickers:
pasingset <- data.frame(V1=c('CWB','EEM','VTI','NAK','GIG'),stringsAsFactors = F)

# this gets you the last closings of your tickers
lastClose <- sapply(pasingset$V1,function(x) xts::last(Cl(get(x))))

# shows the tickers which have a close > 5
pasingset$V1[which(lastClose > 5)]
[1] "CWB" "EEM" "VTI"