New to R

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

New to R

Jim Blackburn
I am newly subscribed to r-project.


I have recently plunged into R on a totally self-taught basis (may not have been the smartest decision!)



I am attempting to download tickers as a time series.  I can successfully create RDA files but I want to convert them to CVS.  Following is the code I have created so far.



if (!require(BatchGetSymbols)) install.packages('BatchGetSymbols')

library(BatchGetSymbols)

tickers <- c('SPY','VCR', 'RPG')

first.date <- Sys.Date()-365

last.date <- Sys.Date

l.out <- BatchGetSymbols(tickers = tickers,

       first.date = first.date,

       last.date = last.date,

cache.folder = file.path("c://Users/Owner/Documents/R",

+    'BGS_Cache') )

print(l.out$df.control)

print(l.out$df.tickers)







I can print(l.out) and see that it contains all the data, but it is not a data.frame



Can anyone help with creating a data.frame and then converting to CSV?



Any help is GREATLY appreciated!



Thanks



Jim


Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: New to R

Bert Gunter-2
Others may help, but I suggest first going through an R tutorial or
two to learn about R's basic data structures, i/o, etc. This list can
help, but cannot substitute for such homework. Some tutorial
recommendations can be found here:
https://www.rstudio.com/online-learning/#r-programming

There are many more, of course.

See also:
?read.table (etc. in the Help page)
?write.table

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Fri, Sep 14, 2018 at 1:56 PM Jim Blackburn
<[hidden email]> wrote:

>
> I am newly subscribed to r-project.
>
>
> I have recently plunged into R on a totally self-taught basis (may not have been the smartest decision!)
>
>
>
> I am attempting to download tickers as a time series.  I can successfully create RDA files but I want to convert them to CVS.  Following is the code I have created so far.
>
>
>
> if (!require(BatchGetSymbols)) install.packages('BatchGetSymbols')
>
> library(BatchGetSymbols)
>
> tickers <- c('SPY','VCR', 'RPG')
>
> first.date <- Sys.Date()-365
>
> last.date <- Sys.Date
>
> l.out <- BatchGetSymbols(tickers = tickers,
>
>        first.date = first.date,
>
>        last.date = last.date,
>
> cache.folder = file.path("c://Users/Owner/Documents/R",
>
> +    'BGS_Cache') )
>
> print(l.out$df.control)
>
> print(l.out$df.tickers)
>
>
>
>
>
>
>
> I can print(l.out) and see that it contains all the data, but it is not a data.frame
>
>
>
> Can anyone help with creating a data.frame and then converting to CSV?
>
>
>
> Any help is GREATLY appreciated!
>
>
>
> Thanks
>
>
>
> Jim
>
>
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: New to R

R help mailing list-2
In reply to this post by Jim Blackburn
If l.out is not a data frame, what is it? A list? A matrix? Some other structure? Try

  str(l.out)
  class(l.out)

and see what you get.

Can't help you convert it to a data frame without knowing what it is.

After you have a data frame, then write.table(), write.csv(), or write.csv2() will "convert" it to a CSV (assuming that's what you meant by "CVS".

-Don

p.s. use reply-all if you want to add that extra information .

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 9/14/18, 11:00 AM, "R-help on behalf of Jim Blackburn" <[hidden email] on behalf of [hidden email]> wrote:

    I am newly subscribed to r-project.
   
   
    I have recently plunged into R on a totally self-taught basis (may not have been the smartest decision!)
   
   
   
    I am attempting to download tickers as a time series.  I can successfully create RDA files but I want to convert them to CVS.  Following is the code I have created so far.
   
   
   
    if (!require(BatchGetSymbols)) install.packages('BatchGetSymbols')
   
    library(BatchGetSymbols)
   
    tickers <- c('SPY','VCR', 'RPG')
   
    first.date <- Sys.Date()-365
   
    last.date <- Sys.Date
   
    l.out <- BatchGetSymbols(tickers = tickers,
   
           first.date = first.date,
   
           last.date = last.date,
   
    cache.folder = file.path("c://Users/Owner/Documents/R",
   
    +    'BGS_Cache') )
   
    print(l.out$df.control)
   
    print(l.out$df.tickers)
   
   
   
   
   
   
   
    I can print(l.out) and see that it contains all the data, but it is not a data.frame
   
   
   
    Can anyone help with creating a data.frame and then converting to CSV?
   
   
   
    Any help is GREATLY appreciated!
   
   
   
    Thanks
   
   
   
    Jim
   
   
    Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
   
   
    [[alternative HTML version deleted]]
   
    ______________________________________________
    [hidden email] mailing list -- To UNSUBSCRIBE and more, see
    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.
   

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: New to R

David Winsemius

> On Sep 14, 2018, at 2:15 PM, MacQueen, Don via R-help <[hidden email]> wrote:
>
> If l.out is not a data frame, what is it? A list? A matrix? Some other structure? Try

I thought it would be one of those variants of a zoo object. Matrix structure with specialized row.names that can handle time-date range operators.

Bert's advice to learn some basic R certainly makes sense. After fixing the two errors in the code and substituting a proper path I get:

str(l.out)
List of 2
 $ df.control:'data.frame': 3 obs. of  6 variables:
  ..$ ticker              : Factor w/ 3 levels "SPY","VCR","RPG": 1 2 3
  ..$ src                 : Factor w/ 1 level "yahoo": 1 1 1
  ..$ download.status     : Factor w/ 1 level "OK": 1 1 1
  ..$ total.obs           : int [1:3] 252 252 252
  ..$ perc.benchmark.dates: num [1:3] 1 1 1
  ..$ threshold.decision  : Factor w/ 1 level "KEEP": 1 1 1
 $ df.tickers:'data.frame': 756 obs. of  10 variables:
  ..$ price.open         : num [1:756] 250 249 250 250 250 ...
  ..$ price.high         : num [1:756] 250 249 250 250 250 ...
  ..$ price.low          : num [1:756] 250 249 249 250 249 ...
  ..$ price.close        : num [1:756] 250 249 250 250 250 ...
  ..$ volume             : num [1:756] 95446300 95432400 46235200 47108100 59574100 ...
  ..$ price.adjusted     : num [1:756] 245 246 246 247 247 ...
  ..$ ref.date           : Date[1:756], format: "2017-09-14" "2017-09-15" "2017-09-18" "2017-09-19" ...
  ..$ ticker             : chr [1:756] "SPY" "SPY" "SPY" "SPY" ...
  ..$ ret.adjusted.prices: num [1:756] NA 0.00135 0.00213 0.001 0.00036 ...
  ..$ ret.closing.prices : num [1:756] NA -0.0036 0.00213 0.001 0.00036 ...


So the data.frame would be:  l.out$df.tickers


It's got the data in a long-format arrangement:

table( l.out$df.tickers$ticker)

RPG SPY VCR
252 252 252
--
David.

>
>  str(l.out)
>  class(l.out)
>
> and see what you get.
>
> Can't help you convert it to a data frame without knowing what it is.
>
> After you have a data frame, then write.table(), write.csv(), or write.csv2() will "convert" it to a CSV (assuming that's what you meant by "CVS".
>
> -Don
>
> p.s. use reply-all if you want to add that extra information .
>
> --
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> Lab cell 925-724-7509
>
>
>
> On 9/14/18, 11:00 AM, "R-help on behalf of Jim Blackburn" <[hidden email] on behalf of [hidden email]> wrote:
>
>    I am newly subscribed to r-project.
>
>
>    I have recently plunged into R on a totally self-taught basis (may not have been the smartest decision!)
>
>
>
>    I am attempting to download tickers as a time series.  I can successfully create RDA files but I want to convert them to CVS.  Following is the code I have created so far.
>
>
>
>    if (!require(BatchGetSymbols)) install.packages('BatchGetSymbols')
>
>    library(BatchGetSymbols)
>
>    tickers <- c('SPY','VCR', 'RPG')
>
>    first.date <- Sys.Date()-365
>
>    last.date <- Sys.Date
>
>    l.out <- BatchGetSymbols(tickers = tickers,
>
>           first.date = first.date,
>
>           last.date = last.date,
>
>    cache.folder = file.path("c://Users/Owner/Documents/R",
>
>    +    'BGS_Cache') )
>
>    print(l.out$df.control)
>
>    print(l.out$df.tickers)
>
>
>
>
>
>
>
>    I can print(l.out) and see that it contains all the data, but it is not a data.frame
>
>
>
>    Can anyone help with creating a data.frame and then converting to CSV?
>
>
>
>    Any help is GREATLY appreciated!
>
>
>
>    Thanks
>
>
>
>    Jim
>
>
>    Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
>     [[alternative HTML version deleted]]
>
>    ______________________________________________
>    [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>    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.
>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: New to R

Michael Dewey-3
In reply to this post by Jim Blackburn
Dear Jim

Without knowing what l.out is this might be tricky. What does str(l.out)
tell you it is. And is CVS a typo for csv?

Michael

On 14/09/2018 19:00, Jim Blackburn wrote:

> I am newly subscribed to r-project.
>
>
> I have recently plunged into R on a totally self-taught basis (may not have been the smartest decision!)
>
>
>
> I am attempting to download tickers as a time series.  I can successfully create RDA files but I want to convert them to CVS.  Following is the code I have created so far.
>
>
>
> if (!require(BatchGetSymbols)) install.packages('BatchGetSymbols')
>
> library(BatchGetSymbols)
>
> tickers <- c('SPY','VCR', 'RPG')
>
> first.date <- Sys.Date()-365
>
> last.date <- Sys.Date
>
> l.out <- BatchGetSymbols(tickers = tickers,
>
>         first.date = first.date,
>
>         last.date = last.date,
>
> cache.folder = file.path("c://Users/Owner/Documents/R",
>
> +    'BGS_Cache') )
>
> print(l.out$df.control)
>
> print(l.out$df.tickers)
>
>
>
>
>
>
>
> I can print(l.out) and see that it contains all the data, but it is not a data.frame
>
>
>
> Can anyone help with creating a data.frame and then converting to CSV?
>
>
>
> Any help is GREATLY appreciated!
>
>
>
> Thanks
>
>
>
> Jim
>
>
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

New to R

Bill Poling
In reply to this post by Jim Blackburn
Hello Jim, as new use"R" myself, 1.5 years I HIGHLY recommend emersion.

Subscribe to :
https://www.r-bloggers.com/

https://stackoverflow.com

http://blog.revolutionanalytics.com/

Anything Hadley Wickam, he has several free e-books.

Depending on  r-help ([hidden email]<mailto:[hidden email]>) is a tough way to go, they can be hard on new users without the formality of:
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html<http://www.R-project.org/posting-guide.html>

Be prepared for partial suggestions that depend on your further research, trial and error!

WHP



From: R-help <[hidden email]> On Behalf Of Jim Blackburn
Sent: Friday, September 14, 2018 2:00 PM
To: [hidden email]
Subject: [R] New to R

I am newly subscribed to r-project.


I have recently plunged into R on a totally self-taught basis (may not have been the smartest decision!)



I am attempting to download tickers as a time series. I can successfully create RDA files but I want to convert them to CVS. Following is the code I have created so far.



if (!require(BatchGetSymbols)) install.packages('BatchGetSymbols')

library(BatchGetSymbols)

tickers <- c('SPY','VCR', 'RPG')

first.date<http://first.date> <- Sys.Date()-365

last.date<http://last.date> <- Sys.Date<http://Sys.Date>

l.out <- BatchGetSymbols(tickers = tickers,

first.date<http://first.date> = first.date<http://first.date>,

last.date<http://last.date> = last.date<http://last.date>,

cache.folder = file.path("c://Users/Owner/Documents/R",

+ 'BGS_Cache') )

print(l.out$df.control)

print(l.out$df.tickers)







I can print(l.out) and see that it contains all the data, but it is not a data.frame



Can anyone help with creating a data.frame and then converting to CSV?



Any help is GREATLY appreciated!



Thanks



Jim


Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986<https://go.microsoft.com/fwlink/?LinkId=550986>> for Windows 10


[[alternative HTML version deleted]]

______________________________________________
[hidden email]<mailto:[hidden email]> mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html<http://www.R-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.

Confidentiality Notice This message is sent from Zelis. ...{{dropped:15}}

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.