I have a matrix B that has three columns. A week number is in the first column, a day number is in the second column, and data is in the third column.
B=1 6 93 15 114 23 115 30 116 37 126 38 116 39 109 58 1210 65 13
What I want to do is turn this into a matrix with 10 rows, one for each week. Whenever there is a week with no data, like week 2 and week 7, I want to add a row with the proper week number, but zeros for the day number and the data. Also, whenever there is a week with more than 1 data entry, like week 6, I want to convert that to one row with 6 as the week number, any value for the day number, and the mean of the data values as the one data value. In other words, I want to convert matrix B into:
C= 1 6 92 0 03 15 114 23 115 30 116 38 117 0 08 0 09 58 1210 65 13
How can I go about doing this?
Best Answer