Search code examples
rquantmodposixct

extract part of a date in a dataframe column


thanks for your help in advance. i am working with the getQuote function in the quantmod package, which returns the following data frame:

enter image description here

is there a way to modify all the dates in the first column to exclude the time stamp, while retaining the data frame structure? i just want the "YYYY-MM-DD" in the first column. i know that if it was a vector of dates, i would use substr(df[,1],1,10). i have also looked into the apply function, with: apply(df[,1],1,substr,1,10).


Solution

  • Another option not mentioned yet:

    tt <- getQuote("AAPL")
    trunc(tt[,1], units='days')
    

    This returns the date in POSIXlt. You can wrap it in as.POSIXct, if you want.