Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a zoo/xts solution. Note that <code>Month</code> is numeric here because you can't mix types in zoo/xts objects.</p> <pre><code>require(xts) # loads zoo too Lines1 &lt;- "Date,Outdoor,Indoor 01/01/2000 01:00,30,25 01/01/2000 02:00,31,26 01/01/2000 03:00,33,24 02/01/2000 01:00,29,25 02/01/2000 02:00,27,26 02/01/2000 03:00,39,24 12/01/2000 02:00,27,26 12/01/2000 03:00,39,24 12/31/2000 23:00,28,25" con &lt;- textConnection(Lines1) z &lt;- read.zoo(con, header=TRUE, sep=",", format="%m/%d/%Y %H:%M", FUN=as.POSIXct) close(con) zz &lt;- merge(z, Month=.indexmon(z), OutdoorAVE=ave(z[,1], .indexmon(z), FUN=mean)) zz # Outdoor Indoor Month OutdoorAVE # 2000-01-01 01:00:00 30 25 0 31.33333 # 2000-01-01 02:00:00 31 26 0 31.33333 # 2000-01-01 03:00:00 33 24 0 31.33333 # 2000-02-01 01:00:00 29 25 1 31.66667 # 2000-02-01 02:00:00 27 26 1 31.66667 # 2000-02-01 03:00:00 39 24 1 31.66667 # 2000-12-01 02:00:00 27 26 11 31.33333 # 2000-12-01 03:00:00 39 24 11 31.33333 # 2000-12-31 23:00:00 28 25 11 31.33333 </code></pre> <p>Update: How do get the above result using two different data sets.</p> <pre><code>Lines2 &lt;- "Date,Month,OutdoorAVE 01/01/2000,Jan,31.33 02/01/2000,Feb,31.67 12/01/2000,Dec,31.33" con &lt;- textConnection(Lines2) z2 &lt;- read.zoo(con, header=TRUE, sep=",", format="%m/%d/%Y", FUN=as.POSIXct, colClasses=c("character","NULL","numeric")) close(con) zz2 &lt;- na.locf(merge(z1, Month=.indexmon(z1), OutdoorAVE=z2))[index(z1)] # same output as zz (above) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload