[R] avoiding too many loops - reshaping data

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Wed Nov 3 21:23:34 CET 2010


I have a data frame like this one:


What I need to get is a data frame like the one below - cities as
rows, brands as columns, and the sums of the "value" within each
city/brand combination in the body of the data frame:

city x   y    z
a    3   23  336
b    7   42  231

I have written a code that involves multiple loops and subindexing -
but it's taking too long.
I am sure there must be a more efficient way of doing it.

Thanks a lot for your hints!

Dimitri Liakhovitski
Ninah Consulting

More information about the R-help mailing list