[R] Help with passing in name of XTS file into write.table as a variable.

MacQueen, Don macqueen1 at llnl.gov
Fri May 9 23:17:47 CEST 2014


It is a simple change.

If you don't save the results of getSymbol() into a variable, then it's
not available for write.table() to write.

Try
  mydata <- getSymbols(ticker,from='1990-01-01')
  write.table( mydata, {etc})

The help for write.table says that "x" (the first argument to
write.table), contains the data to be written to the file (it says
"object" to be written, not "data" to be written, but that's essentially
what it means). The content of your variable tickler is "IBM" so it writes
that to the file.

-Don


p.s., this is so basic that I'd suggest you try to spend some time with
some of the introductory R documentation. Best wishies!


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 5/8/14 4:19 PM, "yannikin at gmail.com" <yannikin at gmail.com> wrote:

>Hi y'all,
>
>I'm using quantmod's getSymbols function, which retrieves data in XTS
>format.
>
>I'm trying to pass "IBM" into the "ticker" variable, then write the table
>referencing "ticker."  However, when I run the write.table command, it
>writes "IBM", not the data inside IBM.
>
>Do you have any thoughts on how to fix this?  I imagine it's a simple
>change.
>
>Thank you much!
>
>ticker="IBM"
>getSymbols(ticker,from='1990-01-01')
>write.table(ticker,file="deleteme.csv", col.names=FALSE, sep=',')
>write.table(as.data.frame(ticker),file="deleteme2.csv", col.names=FALSE,
>sep=',')
>
>-- 
>Yan Wu
>510-333-3188 <http://bigkidsbighearts.org>
>yannikin at gmail.com
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>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