[R] Date format conversion from "2012-09-20" to "2012:09:20"
arun
smartpink111 at yahoo.com
Fri Nov 2 21:02:20 CET 2012
Hi,
This works:
dataspy['20121003/20121009']
# SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
#2012-10-03 144.89 145.43 144.13 145.09 121283100 145.09
#2012-10-04 145.64 146.34 145.44 146.13 124311600 146.13
#2012-10-05 146.91 147.16 145.70 146.14 124842100 146.14
#2012-10-08 145.60 146.12 145.31 145.64 78415400 145.64
#2012-10-09 145.53 145.65 144.15 144.20 148872900 144.20
This also works:
startDate<-"2012-10-03"
endDate<-"2012-10-08"
startEndDate<-paste(startDate,endDate,sep="::")
dataspy[startEndDate,]
# SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
#2012-10-03 144.89 145.43 144.13 145.09 121283100 145.09
#2012-10-04 145.64 146.34 145.44 146.13 124311600 146.13
#2012-10-05 146.91 147.16 145.70 146.14 124842100 146.14
#2012-10-08 145.60 146.12 145.31 145.64 78415400 145.64
A.K.
----- Original Message -----
From: veepsirtt <veepsirtt at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Friday, November 2, 2012 2:41 PM
Subject: Re: [R] Date format conversion from "2012-09-20" to "2012:09:20"
Hi R,
How to get the range of values form startDate to lastDate as given below?.
#*****************************************************************
# Load historical data
#******************************************************************
library('quantmod')
endDate =Sys.Date()
startDate = as.Date(endDate-30, order="ymd")
dataspy = getSymbols("SPY", from = startDate, to=endDate, auto.assign =
FALSE)
lastDate=startDate+5
#subset first 5 days
dataspy['startDate::lastDate']
print(dataspy)
Thanks
veepsirtt
--
View this message in context: http://r.789695.n4.nabble.com/Date-format-conversion-from-2012-09-20-to-2012-09-20-tp4643710p4648258.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list