[R] Data transformation
Santosh Srinivas
santosh.srinivas at gmail.com
Wed Nov 3 08:30:49 CET 2010
Dear Group,
Need to do the following transformation:
I have the dataset
structure(list(Date = structure(1L, .Label = "2010-06-16", class =
"factor"),
ACC.returns1Day = -0.018524832, ACC.returns5Day = 0.000863931,
ACC.returns7Day = -0.019795222, BCC.returns1Day = -0.009861859,
BCC.returns5Day = 0.000850706, BCC.returns7Day = -0.014695715), .Names =
c("Date",
"ACC.returns1Day", "ACC.returns5Day", "ACC.returns7Day", "BCC.returns1Day",
"BCC.returns5Day", "BCC.returns7Day"), class = "data.frame", row.names =
c(NA,
-1L))
I can split the names using:
retNames <- strsplit(names(returns),"\\.returns")
Assuming that the frame has only one row, how do I transform this into
1Day 5Day 7Day
ACC -0.0185 0.0009 -0.0198
BCC -0.0099 0.0009 -0.0147
If I have more than one unique date ... is there some nice structure that I
could put this into where I have the date as the parent and the sub data
structure that gives the data as above for any unique date?
I can always do this with for-loops ... but I think there are easier ways to
achieve this.
Thanks,
S
More information about the R-help
mailing list