missvanilla
2010-Oct-10 02:54 UTC
[R] Help needed for getYahooData in TTR package & writing the Yahoo data to excel
Dear all, I'm totally new to R. Recently I've been trying to use getYahooData in TTR package in order to download stock index daily open/high/low/close. The downloaded data is in the format of Open High Low Close Volume 2000-01-04 18937.45 19187.61 18937.45 19002.86 0 2000-01-05 19003.51 19003.51 18221.82 18542.55 0 2000-01-06 18574.01 18582.74 18168.27 18168.27 0 2000-01-07 18194.05 18285.73 18068.10 18193.41 0 2000-01-11 18246.10 18887.56 18246.10 18850.92 0 2000-01-12 18780.17 18811.87 18626.92 18677.42 0 2000-01-13 18667.18 18845.03 18667.18 18833.29 0 2000-01-14 18882.99 19058.02 18733.83 18956.55 0 2000-01-17 19025.62 19442.58 19025.62 19437.23 0 2000-01-18 19412.47 19412.47 19145.17 19196.57 0 However, when I attempted to write the data to excel using write.table, dates in the first colume become 1,2,3,4 in the excel file. Same problem happened if write.csv was used. If you run these two lines of code you'll get what I meant.. before running the code, package TTR needs to be loaded.>N225 <- getYahooData("^N225", 20000101, ) >write.table(N225,"Nikkei.xls",sep='\t', row.name = TRUE , col.name = NA)Appreciate your kind assistance! Thanks a lot in advance. -- View this message in context: http://r.789695.n4.nabble.com/Help-needed-for-getYahooData-in-TTR-package-writing-the-Yahoo-data-to-excel-tp2970017p2970017.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2010-Oct-10 03:55 UTC
[R] Help needed for getYahooData in TTR package & writing the Yahoo data to excel
On Oct 9, 2010, at 10:54 PM, missvanilla wrote:> > Dear all, > > I'm totally new to R. Recently I've been trying to use getYahooData > in TTR > package in order to download stock index daily open/high/low/close. > The > downloaded data is in the format of > > Open High Low Close Volume > 2000-01-04 18937.45 19187.61 18937.45 19002.86 0 > 2000-01-05 19003.51 19003.51 18221.82 18542.55 0 > 2000-01-06 18574.01 18582.74 18168.27 18168.27 0 > 2000-01-07 18194.05 18285.73 18068.10 18193.41 0 > 2000-01-11 18246.10 18887.56 18246.10 18850.92 0 > 2000-01-12 18780.17 18811.87 18626.92 18677.42 0 > 2000-01-13 18667.18 18845.03 18667.18 18833.29 0 > 2000-01-14 18882.99 19058.02 18733.83 18956.55 0 > 2000-01-17 19025.62 19442.58 19025.62 19437.23 0 > 2000-01-18 19412.47 19412.47 19145.17 19196.57 0 > > However, when I attempted to write the data to excel using > write.table, > dates in the first colume become 1,2,3,4 in the excel file. Same > problem > happened if write.csv was used. > > If you run these two lines of code you'll get what I meant.. before > running > the code, package TTR needs to be loaded. > >> N225 <- getYahooData("^N225", 20000101, ) >> write.table(N225,"Nikkei.xls",sep='\t', row.name = TRUE , col.name >> = NA)There is a well-described problem with write.table files going into Excel. There is no leading item or tab on the first row. You need to insert an extra cell and move the header over one position. Then you won't be misinterpreting your row.names as dates. -- David> > Appreciate your kind assistance! Thanks a lot in advance. > > -- > View this message in context: http://r.789695.n4.nabble.com/Help-needed-for-getYahooData-in-TTR-package-writing-the-Yahoo-data-to-excel-tp2970017p2970017.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.