Re: [R] Reorganize data frame

2011-03-16 Thread Scott Chamberlain
require(reshape2) dcast(stock.returns, Date ~ Ticker) The numbers were changed from their original values, but if you originally created the values Return as.numeric they should stay the same On Wednesday, March 16, 2011 at 9:37 AM, chris99 wrote: Hi group, > > I am trying to convert the organi

Re: [R] Reorganize data frame

2011-03-16 Thread Henrique Dallazuanna
Try this: xtabs(Return ~ Date + Ticker, stock.returns) On Wed, Mar 16, 2011 at 11:37 AM, chris99 wrote: > Hi group, > > I am trying to convert the organization of a data frame so I can do some > correlations between stocks, > > I have something like this: > > stock.returns <- > data.frame(rbind(

Re: [R] Reorganize data frame

2011-03-16 Thread Phil Spector
Here's one way: ans = reshape(stock.returns,idvar='Date', +varying=list(names(stock.returns)[-1]), +direction='long', +times=names(stock.returns)[-1], +v.names='Return',timevar='Ticker') rownames(ans) = NULL ans Date Ticke

[R] Reorganize data frame

2011-03-16 Thread chris99
Hi group, I am trying to convert the organization of a data frame so I can do some correlations between stocks, I have something like this: stock.returns <- data.frame(rbind(c("MSFT","20110301",0.05),c("MSFT","20110302",0.01),c("GOOG","20110301",-0.01),c("GOOG","20110302",0.04))) colnames(stock.