The function sum sums the column of a matrix, and is used here to look at the sums of both columns. However, only the average of the second column is desired. The following statement singles out the second column of grades , uses it as an argument to sum , and divides the result by the number of rows in grades . This file consists of student's names in the first column, and grades in the second column. Rlab has a list-object which allows for convenient association of numeric and string data.
Lists are N-dimensional arrays that are indexed associatively.
With the list we can create elements that are indexed with the student's name. Each element will then contain the student's grade. Alice will contain Alice's grade of 73. First the data must be read and the array grade created. The getline function takes a filename as argument, reads one line, and splits it into numbers and strings.