Is this what you are after (uses the reshape package) > # test data > x <- expand.grid(id=1:5, date=seq(as.Date('2009-01-01'), by='1 day', length=5)) > x$hab <- seq(nrow(x)) # add hab > head(x) id date hab 1 1 2009-01-01 1 2 2 2009-01-01 2 3 3 2009-01-01 3 4 4 2009-01-01 4 5 5 2009-01-01 5 6 1 2009-01-02 6 > require(reshape) > x.melt <- melt(x, measure='hab') > cast(x.melt, id ~ date) id 2009-01-01 2009-01-02 2009-01-03 2009-01-04 2009-01-05 1 1 1 6 11 16 21 2 2 2 7 12 17 22 3 3 3 8 13 18 23 4 4 4 9 14 19 24 5 5 5 10 15 20 25
On Sat, Jun 27, 2009 at 7:40 PM, James Martin <just.strut...@gmail.com>wrote: > All, > > I have three columns of data: id, date, hab. I am trying to set up a matrix > that has the id as the rows, date as columns, and the hab value as the data > values. Each id/date combination can only have one hab value. I would > like > for it to look something like this" > date 1, date 2, date 3. > id > 0001 2 1 2 > 0002 3 5 6 > > I don't know how to set this up properly. I am pretty sure dates cannot be > used in a matrix, but I can easily convert this to an integer. I am mainly > unsure of the functions to use to do this operation. > > Thank you > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.