[R] more dates and data frames

Erin Hodgess erinm.hodgess at gmail.com
Tue Jun 8 21:52:17 CEST 2010


Dear R People:

So thanks to your help, I have the following:


> dog3.df <- read.delim("c:/Users/erin/Documents/dog1.txt",header=FALSE,sep="\t")
> dog3.df
         V1   V2
1  1/1/2000  dog
2  1/1/2000  cat
3  1/1/2000 tree
4  1/1/2000  dog
5  1/2/2000  cat
6  1/2/2000  cat
7  1/2/2000  cat
8  1/2/2000 tree
9  1/3/2000  dog
10 1/3/2000 tree
11 1/6/2000  dog
12 1/6/2000  cat
> dog3.df$V1 <- as.Date(dog3.df$V1,"%m/%d/%Y")
> DF3 <- with(dog3.df,data.frame(Date=V1,V2,1))
> library(reshape)
> cast(formula=Date~V2,data=DF3,value="X1",fill=0)
Aggregation requires fun.aggregate: length used as default
        Date cat dog tree
1 2000-01-01   1   2    1
2 2000-01-02   3   0    1
3 2000-01-03   0   1    1
4 2000-01-06   1   1    0
>

So far, so good.  My new question:  Can I fill in the days which are
"missing"; i.e., 2000-01-04 and 2000-01-05, with zeros for each set,
please?

thanks,
Erin

-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodgess at gmail.com



More information about the R-help mailing list