[R] Reorganize data frame

chris99 cheakes at hotmail.com
Wed Mar 16 15:37:47 CET 2011


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.returns) <- c("Ticker","Date","Return")
stock.returns
  Ticker     Date Return
1   MSFT 20110301   0.05
2   MSFT 20110302   0.01
3   GOOG 20110301  -0.01
4   GOOG 20110302   0.04


And want to convert it to this:

stock.returns <-
data.frame(rbind(c("20110301",0.05,-0.01),c("20110302",0.01,0.04)))
colnames(stock.returns) <- c("Date","MSFT","GOOG")
stock.returns
      Date MSFT  GOOG
1 20110301 0.05 -0.01
2 20110302 0.01  0.04


Can anyone offer any suggestions?

Thanks,
Chris

--
View this message in context: http://r.789695.n4.nabble.com/Reorganize-data-frame-tp3381929p3381929.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list