xts

How to make a set containing count of data in rolling set of buckets

最后都变了- 提交于 2019-12-22 09:47:14
问题 I have the server logs for a months worth of traffic. Partial example below "UploadDateGMT","UserFileSize","TotalBusinessUnits" "2012-01-01 00:00:38","1223","1" "2012-01-01 00:01:16","1302","1" "2012-01-01 00:08:10","1302","1" I would like to convert this into a data set where I have a count of how many bytes of submissions there were in each five minute window on a rolling basis. (i.e. 0-5, 1-6, 2-7, etc.) From this, I could extract maximum load, 95% load, make pretty graphs of load, etc.

R Create a time sequence as xts index based on two columns in data.frame

[亡魂溺海] 提交于 2019-12-21 23:57:30
问题 I have a data.frame like below soc_sec group_count total_creds group_start group_end (chr) (int) (dbl) (date) (date) 1 AA2105480 5 14.0 2005-01-09 2005-05-16 2 AA2105480 7 17.0 2004-08-26 2004-12-10 3 AB4378973 1 0.0 2004-01-21 2004-05-07 4 AB4990257 2 1.0 2014-09-01 2014-12-14 5 AB7777777 5 12.0 2004-01-21 2005-03-22 6 AB7777777 6 15.0 2004-08-26 2004-12-10 7 AB7777777 5 15.0 2005-01-09 2005-05-12 8 AC4285291 2 3.0 2014-09-01 2014-12-14 9 AC4285291 1 3.0 2015-01-12 2015-04-15 10 AC6039874 9

R quantmod::getFinancials

血红的双手。 提交于 2019-12-21 20:44:56
问题 I'm using the quantmod package. I've got a vector of tickers like this : c("AAPL","GOOG","IBM","GS","AMZN","GE") and I want to create a function to calculate the EBIT margin of a stock (= operating income / total revenue). So for a given stock, I use the following piece of code which only works for GE (provided a ".f" is added a the end of the ticker) : require(quantmod) getFinancials("GE",period="A") ebit.margin <- function(stock.ticker.f){ return(stock.ticker$IS$A["Operating Income",]/stock

XTS Apply Family and a Multi Column XTS?

我的未来我决定 提交于 2019-12-21 17:55:47
问题 How do I use the apply family of functions, say apply.daily to a multivariate XTS? So for example: Time,a,b ... 2012-02-11 16:21:24 4.7258 7.7258 2012-02-11 16:26:25 4.9096 12.3796 2012-02-11 16:31:25 4.7904 2.2204 ... How would I use apply.daily and mean to the entire matrix by column. So the result would be a single time stamp for the day, the mean of a for the next column, and the mean of b for the column after that. I would like to do this for arbitrary number columns (the amount of

Plotting two xts objects

穿精又带淫゛_ 提交于 2019-12-21 12:22:25
问题 I'm using xtsExtra to plot two xts objects. Consider the following call to plot.xts: plot.xts(merge(a,b),screens=c(1,2)) which is used to plot the xts objects a and b in two separate panels. How do I control the spacing of the y-axes? Specifically, I'm running into the problem where the y-axis labels come too close or even overlap. Ideally, I would like to specify a minimum padding which is to be maintained between the two y-axis labels. Any help is appreciated! EDIT: A reproducible example:

Aggregating price data to different time horizon in R data.table

让人想犯罪 __ 提交于 2019-12-21 05:42:11
问题 Hi I'm looking to roll up minutely data in a data.table to 5 minutely (or 10 minutely) horizon. I know this is easily done via using xts and the to.minutes5 function, but I prefer not to use xts in this instance as the data set is rather large. Is there an easy way to do this in data.table ? Data example : In this example the period between 21.30 to 21.34 (both inclusive) would have just one row with t = 21.30, open = 0.88703 , high = 0.88799 , low = 0.88702 , close = 0.88798, volume = 43

R Subset XTS weekdays

回眸只為那壹抹淺笑 提交于 2019-12-20 12:08:55
问题 How do I subset an xts object to only include weekdays (Mon-Fri, with Saturday and Sunday excluded)? 回答1: Here's what I'd do: library(xts) data(sample_matrix) sample.xts <- as.xts(sample_matrix, descr='my new xts object') x <- sample.xts['2007'] x[!weekdays(index(x)) %in% c("Saturday", "Sunday")] EDIT : Joshua Ulrich in comments points out a better solution using .indexwday() , one of a family of built-in accessor functions for extracting pieces of the index of xts class objects. Also, like

Improving a function to get stock news data from google in R

时光怂恿深爱的人放手 提交于 2019-12-20 09:24:32
问题 I've written a function to grab and parse news data from Google for a given stock symbol, but I'm sure there are ways it could be improved. For starters, my function returns an object in the GMT timezone, rather than the user's current timezone, and it fails if passed a number greater than 299 (probably because google only returns 300 stories per stock). This is somewhat in response to my own question on stack overflow, and relies heavily on this blog post. tl;dr: how can I improve this

as.POSIXct does not recognise date format = “%Y-%W”

亡梦爱人 提交于 2019-12-20 04:34:33
问题 library(xts) data <- data.frame(year_week = c("2016-46", "2016-47", "2016-48"), satisfaction = c(0.25, 0.45, 0.58)) data = xts(data[-1], order.by = as.POSIXct(data$year_week, format = "%Y-%W")) I want to create an xts object from the data.frame data where the dates keep the format year-week. When I am running the code the columns take the form 2016-12-05 which is incorrect and far from what I am trying to achieve. 回答1: This is a variant on a quasi-FAQ on 'by can one not parse year and month

Copy down last value over a daily period

末鹿安然 提交于 2019-12-20 03:31:10
问题 I have a multi-day XTS object, and I am trying to create an indicator that once true, remains true for the rest of the day. The approach I am trying (but its not working) is combining the na.locf function with the apply daily: output <- apply.daily(x, na.locf) Reproducible code: y <- as.xts(c(NA,NA,1,NA,NA,NA,NA,NA,NA),as.POSIXct(c( "2010-01-05 00:00:00", "2010-01-05 00:04:00", "2010-01-05 00:08:00", "2010-01-05 00:12:00", "2010-01-05 00:16:00", "2010-01-05 00:20:00", "2010-01-06 00:00:00",