0

I have a dataframe for Bitcoin time series data with 3 columns: the date, the closing price (Close) and the return.

> head(BTC.USD)
# A tibble: 6 x 3
Date       Close                       Return
<date>     <dbl>                        <dbl>
1 2015-12-31  430.                      NA     
2 2016-01-01  434.                       0.940 
3 2016-01-02  434.                      -0.0622
4 2016-01-03  431.                      -0.696 
5 2016-01-04  433.                       0.608 
6 2016-01-05  431.                      -0.489 

Now I want to calculate the standard deviation for the return. I used the basic function and this function works:

> sd(BTC.USD$Return, na.rm = TRUE)
[1] 4.10426

Now I want to transform it in a "pipe"-form, so I can implement that into a apply-function, for example. But it doesn't work:

library(tidyverse)
> BTC.USD %>% sd(Return, na.rm = TRUE)
Error in sd(., Return, na.rm = TRUE) : unused argument (Return)

Can someone help me?

TobKel
  • 909
  • 5
  • 17
  • 4
    `BTC.USD %>% pull(Return) %>% sd(na.rm = TRUE)` probably. This extracts column `Return` and then applies `sd` just like in `BTC.USD$Return %>% sd(na.rm = TRUE)` – markus Jan 29 '19 at 18:56
  • Yes. It works. Thank you! – TobKel Jan 29 '19 at 19:00

0 Answers0