Posts

Showing posts with the label conditional

Creating an array with data conditional on another matrix

Creating an array with data conditional on another matrix I know there must be an apply function or ave for this, but I am not quite sure how to do it: I have data: date player market 1: 1-1 1 1 2: 1-1 2 1 3: 1-1 1 2 4: 1-2 2 1 5: 1-2 3 2 6: 1-3 21 1 7: 1-4 1 1 8: 1-4 51 1 9: 1-4 1 1 10: 1-5 1 2 I also have a blank array, which has unique dates on the rows, unique markets on the columns, and unique players for the third dimension. 1 [,,1] 1 2 1-1 1-2 1-3 1-4 1-5 2 [,,2] 1 2 1-1 1-2 1-3 1-4 1-5 etc I want to fill out the array with from the data. I want each point to = 1 if the guy has an entry in the data where he is present for a date and market combination, and 0 if not. So for example, for 1 and 2, they would be filled out as: 1 [,,1] 1 2 1-1 1 1 1-2 0 0 1-3 0 0 1-4 0 1 1-5 0 1 2 [,,2] 1 2 1-1 1 0 1-2 1 ...