Skip to content

better code?

1 message · Spencer Graves

#
OK.  How about the following:

R> x1.df$d. <- as.Date(as.character(x1.df$d), format="%m/%d/%Y")
R> sapply(x1.df, class)
         d         x         y        d.
  "factor" "numeric" "numeric"    "Date"
R>
R> (byLH <- by(x1.df[2:3], x1.df$d., var))
x1.df$d.: 2005-01-01
           x         y
x  1.272688 -0.783719
y -0.783719  0.884866
------------------------------------------------------------
x1.df$d.: 2005-01-08
           x         y
x 1.4893139 0.2845754
y 0.2845754 0.6273839
------------------------------------------------------------
x1.df$d.: 2005-01-15
           x         y
x 0.9992097 0.8719848
y 0.8719848 0.7753879
------------------------------------------------------------
x1.df$d.: 2005-01-22
            x          y
x  1.2269211 -0.8694323
y -0.8694323  0.6161053
------------------------------------------------------------
x1.df$d.: 2005-01-29
             x           y
x 0.072721473 0.006551483
y 0.006551483 1.003923812

spencer graves
##########################################
Hi again!

The solution is good except that the dates are in alpha and not date order.
But this is way better.

Thanks

############################
Hi, Laura:

	  How about the following:
d         x         y
  "factor" "numeric" "numeric"
x1.df$d: 1/1/2005
           x         y
x  1.272688 -0.783719
y -0.783719  0.884866
-------------------------------------------------------------
x1.df$d: 1/15/2005
           x         y
x 0.9992097 0.8719848
y 0.8719848 0.7753879
-------------------------------------------------------------
x1.df$d: 1/22/2005
            x          y
x  1.2269211 -0.8694323
y -0.8694323  0.6161053
-------------------------------------------------------------
x1.df$d: 1/29/2005
             x           y
x 0.072721473 0.006551483
y 0.006551483 1.003923812
-------------------------------------------------------------
x1.df$d: 1/8/2005
           x         y
x 1.4893139 0.2845754
y 0.2845754 0.6273839

	  spencer graves
Laura Holt wrote: