BatchGetSymbols - reshape output

前端 未结 1 1372
庸人自扰
庸人自扰 2021-01-26 13:59

I like to use the advanted of BatchgetSymbols. Any advice how I can best manipulate the output to receive the format below?

symbols_RP <- c(\'VDNR.L\',\'VEUD.         


        
1条回答
  •  南笙
    南笙 (楼主)
    2021-01-26 14:10

    Using dplyr and tidyr. I'm selecting price.adjusted, but you can use any of the prices you need.

    library(dplyr)
    library(tidyr)
    
    prices %>% 
      select(ref.date, ticker, price.adjusted) %>% # select columns before pivot_wider
      pivot_wider(names_from = ticker, values_from = price.adjusted)
    
    # A tibble: 352 x 7
       ref.date   GLRE.L IDTL.L IGLN.L VDEM.L VDNR.L VEUD.L
                       
     1 2019-01-02   NA    NA      25.2   51.0   60.6   30.2
     2 2019-01-03   32.2   4.50   25.3   50.3   59.7   30.1
     3 2019-01-04   32.6   4.47   25.2   51.7   60.9   30.9
     4 2019-01-07   32.8   4.47   25.3   51.8   61.8   31.0
     5 2019-01-08   32.8   4.44   25.2   51.9   62.0   31.3
     6 2019-01-09   33.3   4.43   25.3   53.0   62.7   31.7
     7 2019-01-10   33.5   4.41   25.3   53.2   62.7   31.7
     8 2019-01-11   33.8   4.40   25.3   53.1   62.8   31.6
     9 2019-01-14   33.8   4.41   25.3   52.7   62.7   31.4
    10 2019-01-15   34.0   4.41   25.3   53.1   63.1   31.4
    # ... with 342 more rows
    

    Note from BatchGetSymbols :

    IEMB.L OUT: not enough data (thresh.bad.data = 75%)

    0 讨论(0)
提交回复
热议问题