zoo

Unable to install zoo package (R)

北战南征 提交于 2019-12-10 15:09:16
问题 I am trying to download the zoo package to work with time series using: install.packages("zoo") but I get the following message: --- Please select a CRAN mirror for use in this session --- Warning: unable to access index for repository http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.12 Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.12 Warning messages: 1: In open.connection(con, "r") : unable to connect to 'cran.r-project.org' on

na.locf using group_by from dplyr

半世苍凉 提交于 2019-12-10 14:24:43
问题 I'm trying to use na.locf from package zoo with grouped data using dplyr . I'm using the first solution on this question: Using dplyr window-functions to make trailing values (fill in NA values) library(dplyr);library(zoo) df1 <- data.frame(id=rep(c("A","B"),each=3),problem=c(1,NA,2,NA,NA,NA),ok=c(NA,3,4,5,6,NA)) df1 id problem ok 1 A 1 NA 2 A NA 3 3 A 2 4 4 B NA 5 5 B NA 6 6 B NA NA The problem happens when, within a group, all the data is NA. As you can see in the problem column, the na

converting zoo to dataframe

自闭症网瘾萝莉.ら 提交于 2019-12-10 14:19:15
问题 I converted a zoo time series into a data frame in R and the date became the index of the data frame. Is there a way to have the date represented as a normal column in the data frame? monthly_df <- data.frame(monthly_zoo) head(monthly_zoo) head(monthly_df) 回答1: You want as.data.frame() . Witness: R> library(quantmod) Loading required package: xts Loading required package: TTR Version 0.4-0 included new data defaults. See ?getSymbols. R> IBM <- as.zoo(getSymbols("IBM")) # convert from xts R>

No applicable method for 'time<-' applied to an object of class “c('xts', 'zoo')” [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-10 13:37:16
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Please, put this data structure into R in order to reproduce my example: dX <- structure(c(3272.1, 3271.48, 3281.03, 3267.08, 3260.65, NA, 1616.3, 1620.1

R - Next highest value in a time series

一笑奈何 提交于 2019-12-10 12:12:37
问题 A relatively simple question, but one I can't seem to find any examples. I have simple forex price data which is in a 2 column xts object called subx1: Datetime, Price 2016-09-01 00:00:01, 1.11563 2016-09-01 00:00:01, 1.11564 2016-09-01 00:00:02, 1.11564 2016-09-01 00:00:03, 1.11565 ... and so forth. I'm trying to find the first time after 2pm when the price goes higher than the pre-2pm high which is held in another object's column called daypeakxts$before2.High and Where a sample of

R Replace Intermittent NA Values With Last Observation Carried Forward (NA.LOCF)

人走茶凉 提交于 2019-12-10 12:06:28
问题 Background I neeed to replace the NA's in my data frame by using different methods depending on the NA's nature. My data frame come from a study with repeated measures, where some of the Na's are a result of subjects dropping out while others are a result of intermittent missing measurements, defined as one or a sequence of multiple missing measurements, followed by a measured value. I will be referring to intermittent missing measurements as intermittent NA's. Problem I am having trouble

Using R to create and merge zoo object time series from csv files

梦想的初衷 提交于 2019-12-10 11:45:39
问题 I have a large set of csv files in a single directory. These files contain two columns, Date and Price . The filename of filename.csv contains the unique identifier of the data series. I understand that missing values for merged data series can be handled when these times series data are zoo objects. I also understand that, in using the na.locf(merge() function , I can fill in the missing values with the most recent observations. I want to automate the process of. loading the *.csv file

irregular time series data- can I make it regular? in r

百般思念 提交于 2019-12-10 11:29:16
问题 I have data that was programmed to acquire information every 5 hours which means multiple data points per day. The problem is sometimes the data logger fails or batteries die or whatever and there are missing data or failed attempts. All of my analysis I do is based upon these dates. I need to sort and filter and select everything based on this date/time stamp. As of right now I am going through "long winded" scripts just to select and subset my data. Additionally I have several data loggers

Adding column to zoo object

流过昼夜 提交于 2019-12-10 11:26:22
问题 I have a zoo object z with 10 rows and 2 columns as follow: Date Return 1986-01 0.00308215260513781 1986-02 0.00305355599484584 . . . . . . 1986-10 0.00349830477430457 I need a new zoo object that contains the z object along with a new column X from data frame df . The desired output should look like: Date Return X 1986-01 0.00308215260513781 11 1986-02 0.00305355599484584 12 . . . . . . . . . 1986-10 0.00349830477430457 20 I used the following code: new= merge(z , df$X) However, it gives the

merge two time series with different time granularities

别说谁变了你拦得住时间么 提交于 2019-12-10 10:55:07
问题 I have two CsV files containing time series data. I want to merge the two into a single file. File1 has periodic data at 1-minute intervals. File2 has event-triggered data that is not periodic. The timestamps for data in File2 may or may not coincide with data in File1. I want to merge the two datasets to create a dataset whose timestamps are a union of Data1 and Data2. For timestamps that are not common to both, I want the missing entries for the corresponding dataset to be indicated as NA.