xts

Compute daily, month and annual average of several data sets

倾然丶 夕夏残阳落幕 提交于 2019-12-02 07:52:34
问题 I have a data frame: MS_NR SS_NR DATE HOUR VALUE 1 13095010 68 1/01/2014 0:00:00 9,8 2 13095010 68 1/01/2014 1:00:00 8,0 3 13095010 68 1/01/2014 2:00:00 NA 4 13095010 68 1/01/2014 3:00:00 7,5 5 13095010 68 1/01/2014 4:00:00 7,0 6 13095010 68 1/01/2014 5:00:00 8,5 are temperature observations of a weather station taken every hour, I want to calculate the daily, weekly, monthly and annual averages of several data frames of different weather stations. How can I do this within a loop, so that the

Compute daily, month and annual average of several data sets

六眼飞鱼酱① 提交于 2019-12-02 07:23:16
I have a data frame: MS_NR SS_NR DATE HOUR VALUE 1 13095010 68 1/01/2014 0:00:00 9,8 2 13095010 68 1/01/2014 1:00:00 8,0 3 13095010 68 1/01/2014 2:00:00 NA 4 13095010 68 1/01/2014 3:00:00 7,5 5 13095010 68 1/01/2014 4:00:00 7,0 6 13095010 68 1/01/2014 5:00:00 8,5 are temperature observations of a weather station taken every hour, I want to calculate the daily, weekly, monthly and annual averages of several data frames of different weather stations. How can I do this within a loop, so that the process is not repetitive? When working with hydro-meteorological data, I usually use xts and hydroTSM

r select values below and after a certain value in a dataframe

点点圈 提交于 2019-12-02 06:50:34
问题 i have a question how to select certain values from a table. I have a table with times and values and i want to get the row below and after a certain time. Example-Data.Frame. Time Value 02:51 0.08033405 05:30 0.43456738 09:45 0.36052075 14:02 0.45013807 18:55 0.05745870 ....# and so on Time is coded as character, but can be formatted. Now i have for example the time "6:15" and want to get the values of the time before and after this time from the table (0.43456738 and 0.36052075). The

R: xts timestamp differ from real data timestamp by 1 millisecond

徘徊边缘 提交于 2019-12-02 06:49:15
So I have the following data. tt <- structure(list(Timestamp = c("2018-03-01 09:51:59.969", "2018-03-01 09:51:59.969", "2018-03-01 09:51:59.970", "2018-03-01 09:51:59.971", "2018-03-01 09:51:59.987", "2018-03-01 09:51:59.988"), Mid_Px = c(30755.5, 30755, 30755.5, 30756, 30756.5, 30756.5)), .Names = c("Timestamp", "Mid_Px"), class = "data.frame", row.names = 85774:85779) which looks like this: Timestamp Mid_Px 85774 2018-03-01 09:51:59.969 30755.5 85775 2018-03-01 09:51:59.969 30755.0 85776 2018-03-01 09:51:59.970 30755.5 85777 2018-03-01 09:51:59.971 30756.0 85778 2018-03-01 09:51:59.987 30756

csv data convert to xts

旧巷老猫 提交于 2019-12-02 06:36:06
问题 I have a csv file with 1 minute data from the nasdaq100 for the year 2016. I would like to convert it to xts to work with quantstrat. After the import it looks like this: date open high low close volume adjusted <chr> <dbl> <dbl> <dbl> <dbl> <int> <int> 1 04.01.2016 14:30 48963818 48964272 48952363 48958789 0 0 2 04.01.2016 14:31 48923579 48940259 4891752 48940259 0 0 3 04.01.2016 14:32 48941753 48992466 48941753 48988589 0 0 4 04.01.2016 14:33 48992227 48992227 48948281 48965469 0 0 5 04.01

How to extract dates from apply.monthly function

北城余情 提交于 2019-12-02 06:29:56
If I have a set of daily data, I want to get the minimum value for each month, and the date on which that value occurred. If I use the apply.monthly function, it gives me the minimum value, but the corresponding date is the end of every month, not the date when it actual occurred. How can I get the correct date? library(xts) #create sample data dates<-seq(from=as.Date("1970-01-01"),to=as.Date("1970-12-31"),by=1) x<-sample(1:365,365) ts<-xts(x,dates) #apply function monthly.mins<-apply.monthly(ts,min) monthly.mins apply.monthly uses period.apply , and always indexes at the endpoint of each

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

空扰寡人 提交于 2019-12-02 06:11:35
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. This is a variant on a quasi-FAQ on 'by can one not parse year and month as a date': because a date is day and month and year. Or year, a year and week and day. Otherwise you are

xts subsetting gives incorrect results for months

自古美人都是妖i 提交于 2019-12-02 05:51:41
问题 I am using R 3.2.1 for Mac OS X and seem to have run into incorrect behavior in xts subsetting. In brief, subsetting monthly data give a result that is 1 month lagged from what it should be. Here is a simple example that is similar to an analysis of paleotemperature I am doing: First I will make some test data for the example: xts.test <- xts(rnorm(440*12, mean=0, sd=10),order.by=timeBasedSeq(155001/1989)) This produces a correct xts file AFAICT. Here is the first year of 12 months. head(xts

Extracting nth day of monthly data in r

倾然丶 夕夏残阳落幕 提交于 2019-12-02 05:48:34
I'm facing a problem with making columns using loop. I have a xts dataset and it's second-by-second data. It's start from 2014-09-01 00:00:00 104.172 2014-09-01 00:00:01 104.170 2014-09-01 00:00:02 104.170 2014-09-01 00:00:03 104.170 2014-09-01 00:00:04 104.170 2014-09-01 00:00:05 104.170 and end up with 2014-09-30 03:59:43 109.312 2014-09-30 03:59:44 109.312 2014-09-30 03:59:45 109.312 2014-09-30 03:59:46 109.312 2014-09-30 03:59:47 109.312 2014-09-30 03:59:48 109.313 I would like to make nth day columns from this data set. So I did something like this for(i in 1:30){ask[i] <- ask[.indexmday

XTS time subselect across DST date Linux vs Windows

岁酱吖の 提交于 2019-12-02 04:35:33
On Windows the following subselect code produces an incorrect XTS object, but works correctly on my Ubuntu machine library(xts) theTimes <- seq(from=as.POSIXct('2016-03-10 12:00:00 CDT'), to=as.POSIXct('2016-03-20 12:10:00 CDT'),by=60) ExampleData <- xts(rep(1,length(theTimes)),theTimes) CutExampleData <- ExampleData['T02:00/T16:00'] any(duplicated(index(CutExampleData))) ## Evaluates to TRUE on windows (incorrect) and FALSE on Ubuntu (correctly) SessionInfo on Linux PC: R version 3.3.1 (2016-06-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 16.04.1 LTS locale: [1] LC_CTYPE