zoo

Installation Error When Installing Package from R Forge

筅森魡賤 提交于 2019-12-22 17:59:03
问题 I am trying to update zoo from R Forge. install.packages("zoo", repo = "http://r-forge.r-project.org") But I get the following error Installing package(s) into ‘C:/REVOLU~1/R-COMM~1.3/R-212~1.2/library’ (as ‘lib’ is unspecified) Warning in install.packages : cannot open: HTTP status was '404 Not Found' Warning in install.packages : cannot open: HTTP status was '404 Not Found' Warning in install.packages : unable to access index for repository http://r-forge.r-project.org/bin/windows/contrib/2

Dates appearing as decimals in R plot

久未见 提交于 2019-12-22 10:48:49
问题 I’m trying to plot some data with month data along the x-axis. Unfortunately the months are appearing as decimals. Any ideas? library(zoo) # Requires the zoo library. theMonths <- as.yearmon(c( "Mar 2011", "Apr 2011", "May 2011", "Jun 2011", "Jul 2011", "Aug 2011", "Sep 2011", "Oct 2011", "Nov 2011", "Dec 2011", "Jan 2012", "Feb 2012")) x <- c(1:12) plot(theMonths,x,axes=FALSE) axis(1,theMonths) # Why do the dates appear on the axis as decimals? 回答1: If you look at how the yearmon class

Can rollapply return a list of matrices?

主宰稳场 提交于 2019-12-22 06:25:47
问题 I would like to generate covariance matrices (and mean vectors) using a rolling window. But in all my attempts rollapply stacks the covariance matrices from cov and runs out of pre-allocated space (e.g., if my original data have 40 observations, then rollapply can't return more than 40 rows). Is there a way that I can get rollapply to return a list of matrices? Or to return a data.frame that is larger than the original data.frame , which I can manually split into a list? My end goal is to

Error in ggplot.data.frame : Mapping should be created with aes or aes_string

大憨熊 提交于 2019-12-22 04:07:49
问题 I am having a trouble while extracting the path from a ggplot and am stuck with an error. The image given below explains the result I am looking for: (Done in image editor for explaining purpose) Let's assume that Plot 1 is my original plot. What I am looking for is taking first point as 'F' point and traveling 24hrs from that point. Des %>% mutate(nf = cumsum(ACT=="F")) %>% # build F-to-F groups group_by(nf) %>% mutate(first24h = as.numeric((DateTime-min(DateTime)) < (24*3600))) %>% # find

padr in R: padding at user-defined interval

十年热恋 提交于 2019-12-22 00:36:25
问题 I'm working with time series data at 5-minute time intervals. Some of the 5-minute time series are missing. I'd like to resample the dataset to fill in the missing 5-minute periods with NaN values. I found great information on how to approach this here: R: Insert rows for missing dates/times. I've created a data.frame "df" with a POSIXct timeseries column "time". The pad function in the padr package allows a user to set an interval by the minute, hour, day, etc. interval The interval of the

Dealing with time-periods such as 5 minutes and 30 seconds in R

℡╲_俬逩灬. 提交于 2019-12-21 20:35:09
问题 Is there a good way to deal with time periods such as 05:30 (5 minutes, 30 seconds) in R? Alternatively what's the fastest way to convert it into an integer with just seconds? I can only convert to dates and can't really find a data type for time. I'm using R with zoo. Thanks a lot ! Seconds was the best way to deal with this. I adapted Shane's code below to my purposes, here's the result. # time - time in the format of dd hh:mm:ss # (That's the format used in cvs export from Alcatel CCS

Producing a rolling average of ALL the previous observations per ID in an unbalanced panel data set

南楼画角 提交于 2019-12-21 17:00:01
问题 I am trying to compute rolling means of an unbalanced data set. To illustrate my point I have produced this toy example of my data: ID year Var RollingAvg(Var) 1 2000 2 NA 1 2001 3 2 1 2002 4 2.5 1 2003 2 3 2 2001 2 NA 2 2002 5 2 2 2003 4 3.5 The column RollingAvg(Var) is what I want, but can't get. In words, I am looking for the rolling average of ALL the previous observations of Var for each ID . I have tried using rollapply and ddply in the zoo and the plyr package, but I can't see how to

Use of na.locf function (zoo package) with .SD in data.table

牧云@^-^@ 提交于 2019-12-20 03:17:22
问题 I am trying to fill out all NA's excluding the first two NA's for cols 1 and 4 and three NA's for cols 2 and 3 with most recent non-NA value . Here is my data and code: hh<-structure(list(ka = c(NA, NA, 2, NA, NA, 3, NA, NA, NA, NA), kb = c(NA, NA, NA, 2, NA, NA, 3, NA, NA, NA), gc = c(NA, NA, NA, 3, NA, NA, 6, NA, NA, NA), hc = c(NA, NA, 8, NA, NA, NA, 4, NA, NA, NA)), .Names = c("ka", "kb", "gc", "hc" ), row.names = c(NA, -10L), class = "data.frame") library(zoo) #na.locf library(data.table

Different dates formats in zoo

我只是一个虾纸丫 提交于 2019-12-20 02:56:17
问题 I am finding differences in behavior between two environments running R 2.12.1. In the first one zoo behaves as expected. > library(zoo) > x.date <- as.Date(paste(2003, 2, c(1, 3, 7, 9, 14), sep = "-")) > x <- zoo(rnorm(5), x.date) > index(x) [1] "2003-02-01" "2003-02-03" "2003-02-07" "2003-02-09" "2003-02-14" > as.Date(index(x)) [1] "2003-02-01" "2003-02-03" "2003-02-07" "2003-02-09" "2003-02-14" > sessionInfo() R version 2.12.1 (2010-12-16) Platform: x86_64-unknown-linux-gnu (64-bit) locale

R: RunningTotal in the last 365 days window by Name

怎甘沉沦 提交于 2019-12-19 11:19:13
问题 This is what my data looks like. The rightmost column is my Desired Column. Name EventType EventDate SalesAmount RunningTotal Runningtotal(prior365Days) John Email 1/1/2014 0 0 0 John Sale 2/1/2014 10 10 10 John Sale 7/1/2014 20 30 30 John Sale 4/1/2015 30 60 50 John Webinar 5/1/2015 0 60 50 Tom Email 1/1/2014 0 0 0 Tom Sale 2/1/2014 15 15 15 Tom Sale 7/1/2014 10 25 25 Tom Sale 4/1/2015 25 50 35 Tom Webinar 5/1/2015 0 50 35 I am just trying to get the running total of SalesAmount for each