r - Reducing multi-column xts to single column xts based on provided column indexes -


I have an xts object with multiple columns of the same type. I have an object with another xts object that corresponds to the position of the column in the first object. I would like to generate one-third xts object, in which the value of the column indicated by the respective index in a column is represented. For example:

  # xts.1: 2003-07-30 17:00:00 0.2015173 0.10159303 0.19244332 0.08138396 2003-08-28 17:00:00 0.1890154 0.06889412 0.12700216 0.04631253 2003-09 - 29 17:00:00 0.1336 947 0.08023267 0.09167604 0.02376319 2003-10-30 16:00:00 0.1713496 0.13324238 0.11427968 0.05946272 # Exts: 2003-07-30 17:00:00 1 2003-08-28 17:00:00 4 2003-09-29 17:00:00 2 2003-10-30 16:00:00 3 # Expected results: 2003-07-30 17:00:00 0.2015173 2003-08-28 17:00:00 0.04631253 2003 -09-29 17:00:00 0.08023267 2003-10-30 16:00:00 0.11427968   

I think that this is not something very elementary, but how to do it, If so, this is the only time I have to save.

Your data appears monthly, so I strongly recommend you to POSIXct From index to a date or Ishman index. Otherwise you can participate in problems with timezone and daylight saving time.

One way to solve this problem is to combine xts.1 and xts.2 . , Then loop on all the rows of the resultant object, subscribing the columns based on the merged data by the xts.2 column.

Since your data is monthly, you can find all the comments with the application. .

  & gt; Xts.3 & lt; - Merge (xts.1, xts.2) & gt; apply the. Month (xts.3, work (x) x [, x $ xts.2]) [, 1] 2003-07-30 17:00:00 0.20151730 2003-08-28 17:00:00 0.04631253 2003- 09- 29 17:00:00 0.08023267 2003-10-30 16:00:00 0.11427968    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -