W dniu sobota, 19 kwietnia 2014 11:24:02 UTC+2 użytkownik paul analyst napisał: > > > > W dniu piątek, 18 kwietnia 2014 21:35:10 UTC+2 użytkownik Douglas Bates > napisał: >> >> On Friday, April 18, 2014 11:43:37 AM UTC-5, paul analyst wrote: >>> >>> How quickly convert data from 3 columns to an array of x, y >>> Data are the two columns of text, and the third value: >>> >>> x y z a r 0,31 a r 0,00 a s 0,86 a s 0,80 a t 0,28 b r 0,52 b s >>> 0,79 b s 0,86 b t 0,25 b u 0,15 … … 0,29 q r 0,41 q t 0,61 q v >>> 0,62 >>> The data are: >>> millions of rows >>> hundreds of thousands of "x" >>> a lot of "y" >>> How to quickly build a matrix of "x" in the rows and 'y' in the columns? >>> In a new array i need the sum of "z"? >>> Paul >>> >> >> In the sparse matrix world what you have is known as the coordinate >> representation. You may be able to trick the 'sparse' function into >> creating the matrix for you. I'm not sure how fast that would be. >> >> Otherwise, find the unique values in x and y and convert to numeric >> indexes (the pool function in the DataArrays package can do this for you), >> create the matrix of the appropriate size and run two nested loops. One of >> the beautiful aspects of Julia is that all the time that you spend learning >> how to vectorize calculations in R or Matlab so that you would avoid loops >> has now been wasted. :-) >> >> > Thx Douglas, > my way wihout pacakge and sparse: I used unique(): > > xu=unique(data[:,1]) > yu=unique(data[:,2]) > > data=hcat(data,xu,yu) > now a have indexes of NEWDATA in old table: > > NEWDATA= zeros(lenght(xu),lenght(yu)) > > and one while on the data is finish . > Paul, > Mistake, sorry must be [ after xu=unique(data[:,1]) yu=unique(data[:,2]) ]
xunew=indexin(dane[:,1],xu); yunew=indexin(dane[:,2],yu); data=hcat(data,xunew,yunew) now a have indexes of NEWDATA in old table: NEWDATA= zeros(lenght(xunew),lenght(yunew)) and one while on the data is finish . Paul,