0

I have the following matrix, we can call it MM,

I want to put it in a datatable, but I want to apply a function to column 3, 4 and 5 and by Student_ID which means for

Student_ID = 1

I want to take three separate vector :

MM[1:3,3] , MM[1:3,4], MM[1:3,4]

and apply a function which takes as an input each vector, and two vectors

aa=c(10,20,30) and bb=c(100,200,300)

for instance we can assume that my function returns aa[j]*x+bb[j] and returns the sum of this.

Could you please help me ?

Thanks,

  [Student_ID] [#_of_exams]    [#_of_points_Lesson_1]    [#_of_points_Lesson_2]    [#_of_points_Lesson_3]
 [1,]    1    1 1554932 5006119 2707671
 [2,]    1    2 5477822 8958476 6593003
 [3,]    1    3 7086366  644312 4005567
 [4,]    2    1 9944580  806333 4501512
 [5,]    2    2 4462829  177816 4127272
 [6,]    2    3  211916 6066293 9329248
 [7,]    2    4 3082177 6941193 4284849
 [8,]    2    5 8411017 8687443 7621552
  • Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – Sotos Jul 11 '17 at 13:38
  • I just want to precise that in real my function is not as easy as the one mentioned. There are negative values and I have some max(;0) that is why I cannot just sum all values by Student_Id and multiply by aa and bb. – euromail1 Jul 11 '17 at 15:16

0 Answers0