difficulty creating dataframe

hey everyone,
I'm a fairly new user to R and have been struggling with creating/modifying dataframes. I've been reading "R for Dummies" and scouring the internet for tutorials but am still struggling with this basic exercise (self-directed).

I'm pulling data from the quantmod data sets. I've pulled the VIX close data, and have tried to back into the implied 30day volatility # of S&P 500 options (you can ignore this part - I know it's imprecise). I'm mainly trying to create the first data frame, create a second variable, and then merge the two datasets . using an earlier solution to this post (adopted in the code below), the df was successfully created. However, today i updated rstudio, and now when i try to run this code, some of the output changes (see vix.df portion, in addition to final lines trying to merge the two data sets). Does anyone have any ideas why this might be occurring now? running it just 1hr ago it worked prior to the update. Any help is EXTREMELY appreciated.

pulling vix data

vix <- getSymbols("^VIX", src = "yahoo", auto.assign = FALSE)
vix <- na.omit(vix)
vix <- vix["1995-01-02/2022-01-21"]

head(vix)

vix.df <- as.data.frame(vix)

vix.df

###dataframe appears w/an "x" next to dates. Note: this only happened after I updated to the most recent

version of rstudio

last(vix.df$VIX.Close)

create implied S&P 30D option vol proxy

spxvol <- ((vix.df$VIX.Close)/100)*2

output is numbers (vector?), but not in single column...

spxvol

last(spxvol)

spxvol <- as.data.frame(spxvol)

spxvol <- as.data.frame(spxvol)

head(spxvol)

spxvol_df <- vix.df %>%
as_tibble(rownames = "date") %>%
mutate(spxvol = ((VIX.Close)/100)*2,
date = ymd(date))

Warning message:
Problem while computing date = ymd(date).
i All formats failed to parse. No formats found.

Hi, your dataframe doesn't have a date column. You could do something like this:

# noting that your data is from the quantmod package
library(tidyverse)
library(lubridate)
spx_df <- vix.df %>% 
  as_tibble(rownames = "date") %>% 
  mutate(spxvol = ((VIX.Close)/100)*2,
         date = ymd(date))
  
ggplot(spx_df, aes(x=date, y=spxvol)) +
  geom_line()

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.