2017-10-19 44 views
0

確定,所以我拉代號的列表從其中按日期排序的排序的數據幀。因此,我的符號字符向量是在排序順序:循環讀取的字符向量,以便它被產生的VS字母

> tickers 
    [1] "SPPI" "ZGNX" "ARDM" "PRTK" "GTXI" "HEB" "FCSC" "ACOR" "ALKS" "MNKD" "HRTX" "CTIC" 
[13] "ARLZ" "JAZZ" "VVUS" "DEPO" "OREX" "PLX" "PTIE" "DRRX" "SGEN" "PCRX" "PSDV" "ALIM" 
[25] "INCY" "ATRS" "INSY" "CRIS" "CORT" "EBS" "RGEN" "ARNA" "AMRN" "HALO" "NAVB" "SUPN" 
[37] "EXEL" "IPXL" "IMGN" "DVAX" "SCMP" "TTNP" "ENDP" "AVDL" "AVEO" "TBPH" "DCTH" "ABBV" 
[49] "AMAG" "VNDA" "BMRN" "MDCO" "OMER" "BDSI" "EGRX" "ACRX" "KERX" "NKTR" "PGNX" "AEZS" 
[61] "ENTA" "BCRX" "ADMS" "VRTX" "NBIX" "RMTI" "ADMP" "AMGN" "MNTA" "PTX" "EBIO" "NYMX" 
[73] "VTL" "TTPH" "MACK" "LPTX" "GWPH" "SPHS" "RPRX" "OTIC" "NEOT" "CHRS" "ZFGN" "NEOS" 
[85] "RDHL" "PTLA" "OPK" "CHMA" "ACAD" "NLNK" "AZN" "ICPT" "AAAP" "DERM" "OCUL" "MRNS" 
[97] "RVNC" "CLVS" "GALE" "LPCN" "TSRO" "AMPE" "CYTR" "RARE" "MCRB" "ADMA" "IONS" "VTVT" 
[109] "AUPH" "EARS" "ACRS" "KMDA" "RIGL" "KPTI" "TNXP" "AERI" "NVAX" "VICL" "SRPT" "GILD" 
[121] "ITCI" "GNCA" "ABUS" "CEMP" "TENX" "ALNY" "PLXP" "PTN" "INNL" "ANTH" "CRBP" "BSTC" 
[133] "REPH" "NOVN" "CERC" "HTBX" "LXRX" "HZNP" "SGYP" "OPHT" "AKAO" "LIFE" "PRTO" "VCEL" 
[145] "IRWD" "PBMD" "AMPH" "PFE" "AGRX" "EGLT" "ADHD" "FGEN" "AGN" "GEMP" "OCRX" "CATB" 
[157] "DMTX" "AVIR" "JNJ" "TCON" "SAGE" "ZSAN" "AXON" "MRK" "VRX" "ARDX" "XBIT" "CDTX" 
[169] "TRVN" "CELG" "CMRX" "ARGS" "LJPC" "NDRM" "PBYI" "SCYX" "PTCT" "GALT" "KURA" "AKCA" 
[181] "TGTX" "NVS" "CPRX" "LLY" "GNMX" "BLRX" "XENE" "FOMX" "SNY" "REGN" "RTTR" "CARA" 
[193] "NVCR" "BMY" "ONCE" "GERN" "MESO" "OMED" "MTFB" "EIGR" "ACHN" "AKTX" "XOMA" "CAPR" 
[205] "RDUS" "NTRP" "BPMX" "TXMD" "BTX" "GSK" "CORI" "FOLD" "BLPH" "SBPH" "NVO" "RETA" 
[217] "ECYT" "IMDZ" "MTNB" "ARQL" "LOXO" "ZYME" "RNN" "PIRS" "FPRX" "CALA" "BGNE" "BLUE" 
[229] "CLSN" "CRVS" "GLYC" "JUNO" "IOVA" "RGLS" "XLRN" "ALDX" "EPZM" "SELB" "IMUC" "BLCM" 
[241] "GBT" "STML" "AGIO" "RARX" "ALDR" "ITEK" "IMRN" "QURE" "SVRA" "KDMN" "CBAY" "BVXV" 
[253] "CYTX" "NVIV" "MYOK" "ZYNE" "ESPR" "GLPG" "ABIO" "CVM" "STDY" "CLLS" "INSM" "VSTM" 
[265] "VYGR" "VRNA" "UTHR" "ARRY" "BPMC" "IDRA" "INO" "EPIX" "AGEN" "FENC" "MRTX" "INVA" 
[277] "NBRV" "VSAR" "IPCI" "PRQR" "AZRX" "PRTA" "BHVN" "MYL" "FLXN" "ANAB" "RXDX" 

我想循環讀取這個字符向量的順序是它的產生與字母。

如果我說明數據與加載:

# Note function is store list of commands to perform over a directory of files 

genCHART = function(x){ 
    next.symbol <- tickers[i] # specify to start from first position in vector 
    date.list <- dates[i] # specify to start from first position in vector 
      next.file <- fread(paste0("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=",next.symbol,"&outputsize=full&apikey=6RSYX9BPXKZVXUS9&datatype=csv")) 
      new.df <- data.frame(next.file) 
      head(new.df) 
} 

# Loop calls function in order to process multiple files 
     for (i in 1:length(tickers)){ 
      genCHART(tickers[[i]]) 
     } 

    # loop will do nothing but process and load all tickers.. but its too illustrate the point. 

我們所看到的,如果我們打印行情[I]

> next.symbol 
[1] "ANTH" 

它給我的每字母順序第一個股票。所以它返回從第一個與我上面的訂單開始的代號。我希望它循環通過我的字符列表作爲股票行情的順序。

反正有沒有過來這個?

後期編輯

IF I take a vector of dates: 
> dates 
    [1] "2009-07-05" "2009-07-16" "2009-07-16" "2009-09-04" "2009-10-09" "2009-11-02" 
    [7] "2009-11-02" "2009-12-01" "2009-12-18" "2010-01-22" "2010-01-27" "2010-03-15" 
[13] "2010-03-15" "2010-03-19" "2010-04-09" "2010-04-30" "2010-10-11" "2010-10-28" 
[19] "2011-01-19" "2011-01-28" "2011-02-01" "2011-02-25" "2011-04-29" "2011-06-22" 
[25] "2011-06-24" "2011-06-24" "2011-08-19" "2011-10-31" "2011-11-11" "2011-11-11" 
[31] "2011-11-16" "2011-11-23" "2011-12-08" "2012-01-05" "2012-01-30" "2012-02-17" 

,我想在矢量第一次啓動...

date.list <- dates[i] # specify to start from first position in vector 

不應該上述工作,即使它被包裹在一個函數?

我怎樣才能得到它的工作,讓我讀我的矢量的開始,以及如何做IM把我的號碼時在一個函數,然後運行在循環中的函數來處理多個文件,這項工作?

+2

有一個在你的代碼中沒有循環。另外,我定義了哪裏? – Roland

+0

哎呦 - 我調用這個函數在一個循環...讓我編輯 –

+3

'函數(X)'大概應該是'函數(我)'。 – Roland

回答

0

print(i)=3

i=1 

他回答