and in matlab:
as if they were loaded using textscan:
dates = {'2/1','2/1','2/1','2/2','2/2','2/2'} sites = {'MSFT','GOOG','CISCO','MSFT','GOOG','CISCO'} vals = rand(1,6);
reorganized:
[uDate,uiDate,ujDate] = unique(dates); [uSite,uiSite,ujSite] = unique(sites); sz = [length(uDate),length(uSite)]; valArray = vals(sub2ind(sz,ujDate,ujSite)) valArray = reshape(valArray,sz);
the value for '2/1' 'GOOG' is now in
valArray(find(strcmpi('2/1',uDate),1), find(strcmpi('GOOG',uSite),1))
not as elegant as R, but hey. MATRIXMULTIPLY!
source share