[R] Need to download this data... can someone help?

Rui Barradas ruipbarradas at sapo.pt
Tue Apr 22 22:13:16 CEST 2014


Hello,

I'm getting the data, apparently correct. What I'm getting is the following:


dput(dat)
structure(list(Updated = structure(c(1L, 1L, 1L, 4L, 6L, 5L,
7L, 6L, 2L, 3L), .Label = c("09:06:41 CT 22 Apr 2014", "10:57:42 CT 22 
Apr 2014",
"10:57:46 CT 22 Apr 2014", "11:10:10 CT 22 Apr 2014", "11:21:31 CT 22 
Apr 2014",
"11:21:34 CT 22 Apr 2014", "11:21:46 CT 22 Apr 2014"), class = "factor"),
     `Hi / Lo Limit` = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
     1L, 1L, 1L), .Label = "No Limit / 0.001", class = "factor"),
     Volume = c(0, 41, 0, 27, 3, 61, 256, 221, 20, 16), High = c(NA,
     0.237, NA, 0.159, 0.116, 0.084, 0.058, 0.038, 0.024, 0.016
     ), Low = c(NA, 0.214, 0.16, 0.131, 0.081, 0.063, 0.039, 0.021,
     0.014, 0.009), `Prior Settle` = c(0.253, 0.207, 0.164, 0.124,
     0.09, 0.061, 0.041, 0.026, 0.016, 0.01), Change = c(NA, 0.03,
     -0.002, 0.026, 0.021, 0.017, 0.012, 0.008, 0.006, 0.004),
     Last = c(NA, 0.237, 0.162, 0.15, 0.111, 0.078, 0.053, 0.034,
     0.022, 0.014), `Strike Price` = c(4450, 4500, 4550, 4600,
     4650, 4700, 4750, 4800, 4850, 4900), Last = c(0.006, 0.008,
     0.011, 0.019, 0.031, 0.05, 0.073, 0.105, 0.141, 0.182), Change = c(0,
     -0.002, -0.006, -0.008, -0.012, -0.014, -0.021, -0.024, -0.028,
     -0.031), `Prior Settle` = c(0.006, 0.01, 0.017, 0.027, 0.043,
     0.064, 0.094, 0.129, 0.169, 0.213), Low = c(0.005, 0.008,
     0.011, 0.019, 0.03, 0.047, 0.067, 0.101, 0.137, 0.182), High = 
c(0.006,
     0.01, 0.02, 0.03, 0.046, 0.07, 0.098, 0.134, 0.171, NA),
     Volume = c(4, 81, 2, 76, 2, 3, 1, 0, 0, 0), `Hi / Lo Limit` = 
structure(c(1L,
     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "No Limit / 0.001", 
class = "factor"),
     Updated = structure(c(1L, 2L, 3L, 4L, 5L, 8L, 5L, 6L, 7L,
     1L), .Label = c("09:06:41 CT 22 Apr 2014", "09:11:58 CT 22 Apr 2014",
     "09:22:42 CT 22 Apr 2014", "10:22:14 CT 22 Apr 2014", "11:10:06 CT 
22 Apr 2014",
     "11:17:56 CT 22 Apr 2014", "11:18:10 CT 22 Apr 2014", "11:21:34 CT 
22 Apr 2014"
     ), class = "factor")), .Names = c("Updated", "Hi / Lo Limit",
"Volume", "High", "Low", "Prior Settle", "Change", "Last", "Strike Price",
"Last", "Change", "Prior Settle", "Low", "High", "Volume", "Hi / Lo Limit",
"Updated"), row.names = c(NA, -10L), class = "data.frame")


Rui Barradas

Em 22-04-2014 19:35, Christofer Bogaso escreveu:
> Hi Rui,
>
> Thanks for your prompt reply.
>
> However unfortunately I see that the correct information is not getting
> fetched.
>
> Here I have tried another page:
>
> Link <-
> 'http://www.cmegroup.com/trading/energy/natural-gas/natural-gas_quotes_globex_options.html?optionExpiration=K4#optionProductId=1352&strikeRange=Active'
>
> readHTMLTable((Link), which = 2, header = TRUE, na.strings = "-")
>
> I am not getting right data which is there in the site. Any additional
> adjustment I need to do?
>
> Thanks and regards,
>
>
> On Tue, Apr 22, 2014 at 10:34 PM, Rui Barradas <ruipbarradas at sapo.pt
> <mailto:ruipbarradas at sapo.pt>> wrote:
>
>     Hello,
>
>     I've just noticed that na.strings is not needed and will not be used
>     by readHTMLTable. I was with the false impression that the dots
>     argument was to pass other arguments to read.table, but it's not,
>     they're passed to as.data.frame, that doesn't use na.strings.
>
>     Rui Barradas
>
>     Em 22-04-2014 17:38, Rui Barradas escreveu:
>
>         Hello,
>
>         Have you tried which=2?
>
>         dat <- readHTMLTable(readLines(Link), which = 2, header = TRUE,
>         na.strings = "-")
>
>         dat[, 3:15] <- lapply(dat[, 3:15], function(x)
>         sub("([[:digit:]]) [ab]",
>         "\\1", x))
>         dat[, 3:15] <- lapply(dat[, 3:15],
>         function(x)as.numeric(as.__character(x)))
>
>         str(dat)
>
>
>         Hope this helps,
>
>         Rui Barradas
>
>         Em 22-04-2014 16:30, Christofer Bogaso escreveu:
>
>             Hi Rui,
>
>             Sorry to late reply. Thanks for your pointer.
>
>             However using this method, I am having difficulty to
>             download related
>             data from same site.
>
>             I need to download data from:
>
>
>             'http://www.cmegroup.com/__trading/energy/natural-gas/__natural-gas_quotes_globex___options.html?optionExpiration=__K4#optionProductId=1352
>             <http://www.cmegroup.com/trading/energy/natural-gas/natural-gas_quotes_globex_options.html?optionExpiration=K4#optionProductId=1352>'
>
>
>             So I tried following:
>
>             library(XML)
>             Link <-
>             'http://www.cmegroup.com/__trading/energy/natural-gas/__natural-gas_quotes_globex___options.html?optionExpiration=__K4#optionProductId=1352
>             <http://www.cmegroup.com/trading/energy/natural-gas/natural-gas_quotes_globex_options.html?optionExpiration=K4#optionProductId=1352>'
>
>             readHTMLTable(readLines(Link), which = 1, header = TRUE,
>             na.strings =
>             "-")
>
>             Unfortunately I didnot get what I wanted.
>
>             Can you (or someone) please help me on this?
>
>             Thanks for your time.
>
>
>             On Wed, Apr 9, 2014 at 1:34 AM, Rui Barradas
>             <ruipbarradas at sapo.pt <mailto:ruipbarradas at sapo.pt>
>             <mailto:ruipbarradas at sapo.pt <mailto:ruipbarradas at sapo.pt>>>
>             wrote:
>
>                  Hello,
>
>                  Try the following.
>
>                  library(XML)
>                  URL <-
>
>             "http://www.cmegroup.com/____trading/interest-rates/stir/____eurodollar_quotes_openOutcry.____html
>             <http://www.cmegroup.com/__trading/interest-rates/stir/__eurodollar_quotes_openOutcry.__html>
>
>
>             <http://www.cmegroup.com/__trading/interest-rates/stir/__eurodollar_quotes_openOutcry.__html
>             <http://www.cmegroup.com/trading/interest-rates/stir/eurodollar_quotes_openOutcry.html>>"
>
>
>                  dat <- readHTMLTable(readLines(URL), which=1, header=TRUE,
>                  na.strings = "-")
>
>                  str(dat)
>                  dat[4:10] <- lapply(dat[4:10], function(x)
>             as.numeric(as.character(x)))
>                  head(dat)
>
>
>                  Hope this helps,
>
>                  Rui Barradas
>
>                  Em 08-04-2014 20:40, Christofer Bogaso escreveu:
>
>                      Hi again,
>
>                      I am looking some way to download this data:
>
>
>             http://www.cmegroup.com/____trading/interest-rates/stir/____eurodollar_quotes_openOutcry.____html
>             <http://www.cmegroup.com/__trading/interest-rates/stir/__eurodollar_quotes_openOutcry.__html>
>
>
>             <http://www.cmegroup.com/__trading/interest-rates/stir/__eurodollar_quotes_openOutcry.__html
>             <http://www.cmegroup.com/trading/interest-rates/stir/eurodollar_quotes_openOutcry.html>>
>
>
>                      So far I have tried following code:
>
>                      library(XML)
>                      data <- xmlParse("
>
>             http://www.cmegroup.com/____trading/interest-rates/stir/____eurodollar_quotes_openOutcry.____html
>             <http://www.cmegroup.com/__trading/interest-rates/stir/__eurodollar_quotes_openOutcry.__html>
>
>
>             <http://www.cmegroup.com/__trading/interest-rates/stir/__eurodollar_quotes_openOutcry.__html
>             <http://www.cmegroup.com/trading/interest-rates/stir/eurodollar_quotes_openOutcry.html>>
>
>                      ")
>
>                      However not be able to get in right way.
>
>                      Really appreciate if someone point me on right
>             approach.
>
>                      Thanks for your time.
>
>                               [[alternative HTML version deleted]]
>
>                      __________________________________________________
>             R-help at r-project.org <mailto:R-help at r-project.org>
>             <mailto:R-help at r-project.org <mailto:R-help at r-project.org>>
>             mailing list
>             https://stat.ethz.ch/mailman/____listinfo/r-help
>             <https://stat.ethz.ch/mailman/__listinfo/r-help>
>                      <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>
>                      <http://www.R-project.org/__posting-guide.html
>             <http://www.R-project.org/posting-guide.html>>
>                      and provide commented, minimal, self-contained,
>             reproducible
>             code.
>
>
>
>         ________________________________________________
>         R-help at r-project.org <mailto:R-help at r-project.org> mailing list
>
>         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.
>
>




More information about the R-help mailing list